Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion MiniExcel.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
<Folder Name="/src/">
<File Path="src\Directory.Build.props" />
<File Path="src\Directory.Packages.props" />
<Project Path="src\MiniExcel.OpenXml/MiniExcel.OpenXml.csproj" />
<Project Path="src\MiniExcel.Core\MiniExcel.Core.csproj" />
<Project Path="src\MiniExcel.Csv\MiniExcel.Csv.csproj" />
<Project Path="src\MiniExcel\MiniExcel.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/MiniExcel.Csv.Tests/MiniExcel.Csv.Tests.csproj" />
<Project Path="tests/MiniExcel.OpenXml.Tests/MiniExcel.OpenXml.Tests.csproj" />
<Project Path="tests/MiniExcel.Tests.Common/MiniExcel.Tests.Common.csproj" />
<Project Path="tests\MiniExcel.Core.Tests\MiniExcel.Core.Tests.csproj" />
</Folder>
</Solution>
10 changes: 6 additions & 4 deletions README-V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1589,18 +1589,20 @@ public enum UserTypeEnum
![image](https://user-images.githubusercontent.com/12729184/133116630-27cc7161-099a-48b8-9784-cd1e443af3d1.png)


#### 2. Convert Csv to Xlsx or vice-versa
#### 2. Convert Csv to Xlsx and vice-versa

You can use the `MiniExcelConverter` utility class to convert a file from Csv to Xlsx and vice-versa:

```csharp
MiniExcel.Exporters.GetCsvExporter().ConvertXlsxToCsv(xlsxPath, csvPath);
MiniExcel.Exporters.GetCsvExporter().ConvertCsvToXlsx(csvPath, xlsxPath);
MiniExcelConverter.ConvertXlsxToCsv(xlsxPath, csvPath);
MiniExcelConverter.ConvertCsvToXlsx(csvPath, xlsxPath);

// or

using (var excelStream = new FileStream(path: filePath, FileMode.Open, FileAccess.Read))
using (var csvStream = new MemoryStream())
{
MiniExcel.ConvertXlsxToCsv(excelStream, csvStream);
MiniExcelConverter.ConvertXlsxToCsv(excelStream, csvStream);
}
```

Expand Down
4 changes: 2 additions & 2 deletions V2-Upgrade-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
`MiniExcel.Importers`, `MiniExcel.Exporters` and `MiniExcel.Templaters` will give you access to, respectively, the `MiniExcelImporterProvider`, `MiniExcelExporterProvider` and `MiniExcelTemplaterProvider`.
- This way Excel and Csv query methods are split between the `OpenXmlImporter` and the `CsvImporter`, accessible from the `MiniExcelImporterProvider`.
- The same structure was adopted for export methods through `OpenXmlExporter` and `CsvExporter`, while template methods are instead currently only found in `OpenXmlTemplater`.
- ~~Csv methods are only available if the MiniExcel.Csv package is installed, which is pulled down automatically when the full MiniExcel package is downloaded.~~
We're still pondering whether this is the best way to move forward with the library, currently only the full MiniExcel package is available.
- Csv methods are only available if the MiniExcel.Csv package is installed, which is pulled down automatically when the full MiniExcel package is downloaded.
- You can only access the conversion methods `ConvertCsvToXlsx` and `ConvertXlsxToCsv` from the `MiniExcelConverter` utility class, which is part of the full MiniExcel package.
- If the full MiniExcel package is downloaded, the previous namespace will coexist along the new one, containing the original static methods' signatures, which have become a facade for the aferomentioned providers.
- `IConfiguration` is now `IMiniExcelConfiguration`, but most methods now require the proper implementation (`OpenXmlConfiguration` or `CsvConfiguration`) to be provided rather than the interface
- MiniExcel now fully supports asynchronous streaming the queries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using DocumentFormat.OpenXml.Spreadsheet;
using MiniExcelLib.Benchmarks.Utils;
using MiniExcelLib.Core;
using MiniExcelLib.Core.FluentMapping;
using MiniExcelLib.OpenXml.Api;
using MiniExcelLib.OpenXml.FluentMapping;
using MiniExcelLib.OpenXml.FluentMapping.Api;
using NPOI.XSSF.UserModel;
using OfficeOpenXml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using DocumentFormat.OpenXml.Spreadsheet;
using ExcelDataReader;
using MiniExcelLib.Core;
using MiniExcelLib.Core.FluentMapping;
using MiniExcelLib.OpenXml.Api;
using MiniExcelLib.OpenXml.FluentMapping;
using MiniExcelLib.OpenXml.FluentMapping.Api;
using NPOI.XSSF.UserModel;
using OfficeOpenXml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using ClosedXML.Report;
using MiniExcelLib.Benchmarks.Utils;
using MiniExcelLib.Core;
using MiniExcelLib.Core.FluentMapping;
using MiniExcelLib.OpenXml.Api;
using MiniExcelLib.OpenXml.FluentMapping;
using MiniExcelLib.OpenXml.FluentMapping.Api;

namespace MiniExcelLib.Benchmarks.BenchmarkSections;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BenchmarkDotNet.Attributes;
using MiniExcelLib.Benchmarks.Utils;
using MiniExcelLib.Core;
using MiniExcelLib.OpenXml.Api;

namespace MiniExcelLib.Benchmarks.BenchmarkSections;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MiniExcel.Core\MiniExcel.Core.csproj" />
<ProjectReference Include="..\..\src\MiniExcel\MiniExcel.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/MiniExcel.Core/Abstractions/IMappingCellStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace MiniExcelLib.Core.Abstractions;

public interface IMappingCellStream
{
IMiniExcelWriteAdapter CreateAdapter();
}
22 changes: 12 additions & 10 deletions src/MiniExcel.Core/Attributes/MiniExcelColumnAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace MiniExcelLib.Core.Attributes;
namespace MiniExcelLib.Core.Attributes;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class MiniExcelColumnAttribute : Attribute
{
private int _index = -1;
private string? _xName;

internal int FormatId { get; set; } = -1;

public string? Name { get; set; }
public string[]? Aliases { get; set; } = [];
public string[]? Aliases { get; set; } = [];
public string? Format { get; set; }
public bool Ignore { get; set; }

internal int FormatId { get; private set; } = -1;
public double Width { get; set; } = 9.28515625;
public string? Format { get; set; }
public bool Ignore { get; set; }
public ColumnType Type { get; set; } = ColumnType.Value;

public int Index
Expand All @@ -24,7 +24,7 @@ public int Index
public string? IndexName
{
get => _xName;
set => Init(ColumnHelper.GetColumnIndex(value), value);
set => Init(CellReferenceConverter.GetNumericalIndex(value), value);
}

private void Init(int index, string? columnName = null)
Expand All @@ -33,19 +33,21 @@ private void Init(int index, string? columnName = null)
throw new ArgumentOutOfRangeException(nameof(index), index, $"Column index {index} must be greater or equal to zero.");

_index = index;
_xName ??= columnName ?? ColumnHelper.GetAlphabetColumnName(index);
_xName ??= columnName ?? CellReferenceConverter.GetAlphabeticalIndex(index);
}

public void SetFormatId(int formatId) => FormatId = formatId;
}

public enum ColumnType { Value, Formula }

public class DynamicExcelColumn : MiniExcelColumnAttribute
{
public string Key { get; set; }
public Func<object, object> CustomFormatter { get; set; }
public Func<object, object>? CustomFormatter { get; set; }

public DynamicExcelColumn(string key)
{
Key = key;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ public class MiniExcelColumnIndexAttribute : Attribute
{
public int ExcelColumnIndex { get; set; }
internal string? ExcelXName { get; set; }
public MiniExcelColumnIndexAttribute(string columnName) => Init(ColumnHelper.GetColumnIndex(columnName), columnName);
public MiniExcelColumnIndexAttribute(string columnName) => Init(CellReferenceConverter.GetNumericalIndex(columnName), columnName);
public MiniExcelColumnIndexAttribute(int columnIndex) => Init(columnIndex);

private void Init(int columnIndex, string? columnName = null)
{
if (columnIndex < 0)
throw new ArgumentOutOfRangeException(nameof(columnIndex), columnIndex, $"Column index {columnIndex} must be greater or equal to zero.");

ExcelXName ??= columnName ?? ColumnHelper.GetAlphabetColumnName(columnIndex);
ExcelXName ??= columnName ?? CellReferenceConverter.GetAlphabeticalIndex(columnIndex);
ExcelColumnIndex = columnIndex;
}
}
5 changes: 0 additions & 5 deletions src/MiniExcel.Core/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
global using System.Collections;
global using System.Data;
global using System.Globalization;
global using System.IO.Compression;
global using System.Reflection;
global using System.Runtime.CompilerServices;
global using System.Text;
global using System.Text.RegularExpressions;
global using System.Xml;
global using MiniExcelLib.Core.Abstractions;
global using MiniExcelLib.Core.Helpers;
global using MiniExcelLib.Core.OpenXml;
global using MiniExcelLib.Core.OpenXml.Utils;
global using MiniExcelLib.Core.Reflection;
global using Zomp.SyncMethodGenerator;
18 changes: 18 additions & 0 deletions src/MiniExcel.Core/Helpers/AsyncEnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace MiniExcelLib.Core.Helpers;

public static class AsyncEnumerableExtensions
{
public static async Task<List<T>> CreateListAsync<T>(this IAsyncEnumerable<T> enumerable, CancellationToken cancellationToken = default)
{
List<T> list = [];
await foreach (var item in enumerable.WithCancellation(cancellationToken).ConfigureAwait(false))
{
list.Add(item);
}

return list;
}

// needed by the SyncGenerator
public static List<T> CreateList<T>(this IEnumerable<T> enumerable) => [..enumerable];
}
38 changes: 0 additions & 38 deletions src/MiniExcel.Core/Helpers/AttributeExtension.cs

This file was deleted.

26 changes: 26 additions & 0 deletions src/MiniExcel.Core/Helpers/AttributeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace MiniExcelLib.Core.Helpers;

public static class AttributeExtensions
{
private static TValue? GetValueOrDefault<TAttribute, TValue>(
Func<TAttribute, TValue> selector,
TAttribute? attr) where TAttribute : Attribute
{
return attr is not null ? selector(attr) : default;
}

public static TAttribute? GetAttribute<TAttribute>(this MemberInfo prop, bool isInherit = true)
where TAttribute : Attribute
{
return prop.GetAttributeValue((TAttribute attr) => attr, isInherit);
}

public static TValue? GetAttributeValue<TAttribute, TValue>(
this MemberInfo prop,
Func<TAttribute, TValue> selector,
bool isInherit = true ) where TAttribute : Attribute
{
var attr = Attribute.GetCustomAttribute(prop, typeof(TAttribute), isInherit) as TAttribute;
return GetValueOrDefault(selector, attr);
}
}
Loading
Loading