Skip to content

Commit 8fd3e38

Browse files
Renaming the "new" MiniExcel class to MiniExcelV2 (#1010)
* Renamed MiniExcelLib.MiniExcel class to MiniExcelV2 This change was adopted to avoid confusion with the `MiniExcelLibs.MiniExcel` facade class containing the V1 methods' signatures. Users will be able to unambiguosly distinguish between the legacy facade methods and the new idiomatic ones. * Added summary to the MiniExcel facade class The remarks explain the purpose of the class and advise the consumers of the library to favor the usage of the new `MiniExcelV2` class instead for a better user experience. * Updated docs to reflect last changes and fixed a few minor mistakes * Clarified the difference between the `MiniExcel` and `MiniExcelV2` classes in the upgrade notes
1 parent d02e49a commit 8fd3e38

45 files changed

Lines changed: 279 additions & 270 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README_V2.md‎

Lines changed: 72 additions & 72 deletions
Large diffs are not rendered by default.

‎V2-Upgrade-Notes.md‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
## MiniExcel 2.0 Upgrade Notes
22

33
- Support for .NET Framework 4.5 was dropped, the minimum supported Framework version is now 4.6.2.
4-
- The root namespace was changed from `MiniExcelLibs` to `MiniExcelLib`.
5-
- Instead of having all methods being part of the `MiniExcel` static class, the functionalities are now split into 3 providers:
6-
`MiniExcel.Importers`, `MiniExcel.Exporters` and `MiniExcel.Templaters` will give you access to, respectively, the `MiniExcelImporterProvider`, `MiniExcelExporterProvider` and `MiniExcelTemplaterProvider`.
4+
- The root namespace was changed from `MiniExcelLibs` to `MiniExcelLib`; there is also a new entry point to the library, the static class `MiniExcelV2`. The original class has been turned into a facade for backwards compatibility reasons (more on that later).
5+
- Instead of having all methods being part of a single static class, the functionalities are now split into 3 providers:
6+
`MiniExcelV2.Importers`, `MiniExcelV2.Exporters` and `MiniExcelV2.Templaters` will give you access to, respectively, the `MiniExcelImporterProvider`, `MiniExcelExporterProvider` and `MiniExcelTemplaterProvider`.
77
- This way Excel and Csv query methods are split between the `OpenXmlImporter` and the `CsvImporter`, accessible from the `MiniExcelImporterProvider`.
88
- The same structure was adopted for export methods through `OpenXmlExporter` and `CsvExporter`, while template methods are instead currently only found in `OpenXmlTemplater`.
99
- OpenXml and Csv methods are only available if the respective `MiniExcel.OpenXml` and `MiniExcel.Csv` packages are downloaded, or if the complete `MiniExcel` package is installed.
1010
- You can only access the conversion methods `ConvertCsvToXlsx` and `ConvertXlsxToCsv` from the `MiniExcelConverter` utility class, which is part of the full MiniExcel package.
11-
- 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.
11+
- If the full MiniExcel package is downloaded, the previous namespace will coexist along the new one, containing a facade `MiniExcel` static class with all the original methods' signatures for backwards compatibility.
1212
- `IConfiguration` is now `IMiniExcelConfiguration`, but most methods now require the proper implementation (`OpenXmlConfiguration` or `CsvConfiguration`) to be provided rather than the interface
13-
- MiniExcel now fully supports asynchronous streaming the queries,
13+
- MiniExcel now fully supports asynchronously streaming the queries,
1414
so the return type for `OpenXmlImporter.QueryAsync` is `IAsyncEnumerable<T>` instead of `Task<IEnumerable<T>>`
1515
- When applying a template, unlike version 1.x, the flag for overwriting an already existing file must be provided explicitly.
16-
- `leaveOpen` parameter has been added to most methods that take a stream as input in both `OpenXmlImporter` and `CsvImporter` to configure whether the stream must be disposed after the operation performed is completed.
17-
- `useHeaderRow` parameter in multiple `OpenXmlImporter` methods has been renamed to `hasHeaderRow` for making its usage clearer.
16+
- A `leaveOpen` parameter has been added to most methods that take a stream as input in both `OpenXmlImporter` and `CsvImporter` to configure whether the stream must be disposed after the operation performed is completed.
17+
- The `useHeaderRow` parameter in multiple `OpenXmlImporter` and `CsvImporter` methods has been renamed to `hasHeaderRow` for making its usage clearer.
1818
- `CsvExporter.Export` API methods, not being required to return the same type of `OpenXmlExporter.Export`, now return `int` instead of `int[]`.
19-
- Most `OpenXmlImporter` and `CsvImporter` methods that take a stream as input now take an additional `leaveOpen` boolean parameter, to set to `true` explicitly if you want the stream to be left open at the of the operation.

‎benchmarks/MiniExcel.Benchmarks/BenchmarkSections/CreateExcelBenchmark.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void SetUp()
2424
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
2525
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
2626

27-
_exporter = MiniExcel.Exporters.GetOpenXmlExporter();
27+
_exporter = MiniExcelV2.Exporters.GetOpenXmlExporter();
2828

2929
var simpleRegistry = new MappingRegistry();
3030
simpleRegistry.Configure<DemoDto>(config =>
@@ -40,7 +40,7 @@ public void SetUp()
4040
config.Property(x => x.Column9).ToCell("I1");
4141
config.Property(x => x.Column10).ToCell("J1");
4242
});
43-
_simpleMappingExporter = MiniExcel.Exporters.GetMappingExporter(simpleRegistry);
43+
_simpleMappingExporter = MiniExcelV2.Exporters.GetMappingExporter(simpleRegistry);
4444
}
4545

4646
[Benchmark(Description = "MiniExcel Create Xlsx")]

‎benchmarks/MiniExcel.Benchmarks/BenchmarkSections/QueryExcelBenchmark.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void SetUp()
2323
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
2424
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
2525

26-
_importer = MiniExcel.Importers.GetOpenXmlImporter();
26+
_importer = MiniExcelV2.Importers.GetOpenXmlImporter();
2727

2828
// Setup mapping for query (matches CreateExcelBenchmark mapping)
2929
var registry = new MappingRegistry();
@@ -40,7 +40,7 @@ public void SetUp()
4040
config.Property(x => x.Column9).ToCell("I1");
4141
config.Property(x => x.Column10).ToCell("J1");
4242
});
43-
_mappingImporter = MiniExcel.Importers.GetMappingImporter(registry);
43+
_mappingImporter = MiniExcelV2.Importers.GetMappingImporter(registry);
4444
}
4545

4646
[Benchmark(Description = "MiniExcel QueryFirst")]

‎benchmarks/MiniExcel.Benchmarks/BenchmarkSections/TemplateExcelBenchmark.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ public class Employee
2222
[GlobalSetup]
2323
public void Setup()
2424
{
25-
_templater = MiniExcel.Templaters.GetOpenXmlTemplater();
26-
_exporter = MiniExcel.Exporters.GetOpenXmlExporter();
25+
_templater = MiniExcelV2.Templaters.GetOpenXmlTemplater();
26+
_exporter = MiniExcelV2.Exporters.GetOpenXmlExporter();
2727

2828
var registry = new MappingRegistry();
2929
registry.Configure<Employee>(config =>
3030
{
3131
config.Property(x => x.Name).ToCell("A2");
3232
config.Property(x => x.Department).ToCell("B2");
3333
});
34-
_mappingTemplater = MiniExcel.Templaters.GetMappingTemplater(registry);
34+
_mappingTemplater = MiniExcelV2.Templaters.GetMappingTemplater(registry);
3535
}
3636

3737
[Benchmark(Description = "MiniExcel Fill Template")]

‎benchmarks/MiniExcel.Benchmarks/BenchmarkSections/XlsxAsyncBenchmark.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class XlsxAsyncBenchmark : BenchmarkBase
1212
[GlobalSetup]
1313
public void Setup()
1414
{
15-
_exporter = MiniExcel.Exporters.GetOpenXmlExporter();
16-
_templater = MiniExcel.Templaters.GetOpenXmlTemplater();
15+
_exporter = MiniExcelV2.Exporters.GetOpenXmlExporter();
16+
_templater = MiniExcelV2.Templaters.GetOpenXmlTemplater();
1717
}
1818

1919
[Benchmark(Description = "MiniExcel Create Xlsx Async")]

‎src/MiniExcel.Core/MiniExcel.cs‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎src/MiniExcel.Core/MiniExcelV2.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using MiniExcelLib.Core;
2+
3+
// ReSharper disable once CheckNamespace
4+
namespace MiniExcelLib;
5+
6+
public static class MiniExcelV2
7+
{
8+
public static readonly MiniExcelExporterProvider Exporters = new();
9+
public static readonly MiniExcelImporterProvider Importers = new();
10+
public static readonly MiniExcelTemplaterProvider Templaters = new();
11+
}
12+
13+
[Obsolete("This class will be removed in the full release, use MiniExcelV2 instead.", true)]
14+
public static class MiniExcel
15+
{
16+
public static readonly MiniExcelExporterProvider Exporters = new();
17+
public static readonly MiniExcelImporterProvider Importers = new();
18+
public static readonly MiniExcelTemplaterProvider Templaters = new();
19+
}

‎src/MiniExcel/MiniExcel.cs‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@
66
using MiniExcelLib.OpenXml.Picture;
77
using Zomp.SyncMethodGenerator;
88

9-
using NewMiniExcel = MiniExcelLib.MiniExcel;
109
using NewOpenXmlConfiguration = MiniExcelLib.OpenXml.OpenXmlConfiguration;
10+
using NewCsvConfiguration = MiniExcelLib.Csv.CsvConfiguration;
1111
using MiniExcelDataReader = MiniExcelLib.Core.MiniExcelDataReaderBase;
1212

1313
// ReSharper disable once CheckNamespace
1414
namespace MiniExcelLibs;
1515

16+
/// <summary>
17+
/// This class is a facade containing the methods' signatures from the V1 API, preserved for backwards compatibility.
18+
/// We encourage the users to take advantage of the idiomatic <see cref="MiniExcelV2"/> class instead
19+
/// for a compartmentalized, richer and more flexible API.
20+
/// </summary>
1621
public static partial class MiniExcel
1722
{
18-
private static readonly OpenXmlExporter ExcelExporter = NewMiniExcel.Exporters.GetOpenXmlExporter();
19-
private static readonly OpenXmlImporter ExcelImporter = NewMiniExcel.Importers.GetOpenXmlImporter();
20-
private static readonly OpenXmlTemplater ExcelTemplater = NewMiniExcel.Templaters.GetOpenXmlTemplater();
23+
private static readonly OpenXmlExporter ExcelExporter = MiniExcelV2.Exporters.GetOpenXmlExporter();
24+
private static readonly OpenXmlImporter ExcelImporter = MiniExcelV2.Importers.GetOpenXmlImporter();
25+
private static readonly OpenXmlTemplater ExcelTemplater = MiniExcelV2.Templaters.GetOpenXmlTemplater();
2126

22-
private static readonly CsvExporter CsvExporter = NewMiniExcel.Exporters.GetCsvExporter();
23-
private static readonly CsvImporter CsvImporter = NewMiniExcel.Importers.GetCsvImporter();
27+
private static readonly CsvExporter CsvExporter = MiniExcelV2.Exporters.GetCsvExporter();
28+
private static readonly CsvImporter CsvImporter = MiniExcelV2.Importers.GetCsvImporter();
2429

2530

2631
[CreateSyncVersion]
@@ -62,7 +67,7 @@ public static async Task<int> InsertAsync(string path, object value, string shee
6267
return type switch
6368
{
6469
ExcelType.XLSX => await ExcelExporter.InsertSheetAsync(path, value, sheetName, printHeader, overwriteSheet, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
65-
ExcelType.CSV => await CsvExporter.AppendAsync(path, value, printHeader, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
70+
ExcelType.CSV => await CsvExporter.AppendAsync(path, value, printHeader, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
6671
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
6772
};
6873
}
@@ -76,7 +81,7 @@ public static async Task<int> InsertAsync(this Stream stream, object value, stri
7681
return type switch
7782
{
7883
ExcelType.XLSX => await ExcelExporter.InsertSheetAsync(stream, value, sheetName, printHeader, overwriteSheet, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
79-
ExcelType.CSV => await CsvExporter.AppendAsync(stream, value, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
84+
ExcelType.CSV => await CsvExporter.AppendAsync(stream, value, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
8085
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
8186
};
8287
}
@@ -90,7 +95,7 @@ public static async Task<int[]> SaveAsAsync(string path, object value, bool prin
9095
return type switch
9196
{
9297
ExcelType.XLSX => await ExcelExporter.ExportAsync(path, value, printHeader, sheetName, overwriteFile, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
93-
ExcelType.CSV => [await CsvExporter.ExportAsync(path, value, printHeader, overwriteFile, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
98+
ExcelType.CSV => [await CsvExporter.ExportAsync(path, value, printHeader, overwriteFile, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
9499
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
95100
};
96101
}
@@ -104,7 +109,7 @@ public static async Task<int[]> SaveAsAsync(this Stream stream, object value, bo
104109
return type switch
105110
{
106111
ExcelType.XLSX => await ExcelExporter.ExportAsync(stream, value, printHeader, sheetName, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
107-
ExcelType.CSV => [await CsvExporter.ExportAsync(stream, value, printHeader, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
112+
ExcelType.CSV => [await CsvExporter.ExportAsync(stream, value, printHeader, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
108113
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
109114
};
110115
}
@@ -119,7 +124,7 @@ public static async Task<int[]> SaveAsAsync(this Stream stream, object value, bo
119124
return type switch
120125
{
121126
ExcelType.XLSX => ExcelImporter.QueryAsync<T>(path, sheetName, startCell, !hasHeader, configuration as NewOpenXmlConfiguration, cancellationToken),
122-
ExcelType.CSV => CsvImporter.QueryAsync<T>(path, !hasHeader, configuration as Csv.CsvConfiguration, cancellationToken),
127+
ExcelType.CSV => CsvImporter.QueryAsync<T>(path, !hasHeader, configuration as NewCsvConfiguration, cancellationToken),
123128
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
124129
};
125130
}
@@ -134,7 +139,7 @@ public static async Task<int[]> SaveAsAsync(this Stream stream, object value, bo
134139
return type switch
135140
{
136141
ExcelType.XLSX => ExcelImporter.QueryAsync<T>(stream, sheetName, startCell, !hasHeader, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken),
137-
ExcelType.CSV => CsvImporter.QueryAsync<T>(stream, !hasHeader, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken),
142+
ExcelType.CSV => CsvImporter.QueryAsync<T>(stream, !hasHeader, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken),
138143
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
139144
};
140145
}
@@ -146,7 +151,7 @@ public static IAsyncEnumerable<dynamic> QueryAsync(string path, bool useHeaderRo
146151
return type switch
147152
{
148153
ExcelType.XLSX => ExcelImporter.QueryAsync(path, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, cancellationToken),
149-
ExcelType.CSV => CsvImporter.QueryAsync(path, useHeaderRow, configuration as Csv.CsvConfiguration, cancellationToken),
154+
ExcelType.CSV => CsvImporter.QueryAsync(path, useHeaderRow, configuration as NewCsvConfiguration, cancellationToken),
150155
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
151156
};
152157
}
@@ -158,7 +163,7 @@ public static IAsyncEnumerable<dynamic> QueryAsync(this Stream stream, bool useH
158163
return type switch
159164
{
160165
ExcelType.XLSX => ExcelImporter.QueryAsync(stream, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken),
161-
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration,leaveOpen: true, cancellationToken),
166+
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as NewCsvConfiguration,leaveOpen: true, cancellationToken),
162167
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
163168
};
164169
}
@@ -191,7 +196,7 @@ public static IAsyncEnumerable<dynamic> QueryRangeAsync(this Stream stream, bool
191196
return type switch
192197
{
193198
ExcelType.XLSX => ExcelImporter.QueryRangeAsync(stream, useHeaderRow, sheetName, startCell, endCell, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken),
194-
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken),
199+
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken),
195200
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
196201
};
197202
}
@@ -285,7 +290,7 @@ public static async Task<DataTable> QueryAsDataTableAsync(string path, bool useH
285290
return type switch
286291
{
287292
ExcelType.XLSX => await ExcelImporter.QueryAsDataTableAsync(path, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, cancellationToken).ConfigureAwait(false),
288-
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(path, useHeaderRow, configuration as Csv.CsvConfiguration, cancellationToken).ConfigureAwait(false),
293+
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(path, useHeaderRow, configuration as NewCsvConfiguration, cancellationToken).ConfigureAwait(false),
289294
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
290295
};
291296
}
@@ -298,7 +303,7 @@ public static async Task<DataTable> QueryAsDataTableAsync(this Stream stream, bo
298303
return type switch
299304
{
300305
ExcelType.XLSX => await ExcelImporter.QueryAsDataTableAsync(stream, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
301-
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
306+
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(stream, useHeaderRow, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
302307
_ => throw new InvalidDataException($"Excel type {type} is not a valid Excel type")
303308
};
304309
}
@@ -326,7 +331,7 @@ public static async Task<ICollection<string>> GetColumnsAsync(string path, bool
326331
return type switch
327332
{
328333
ExcelType.XLSX => await ExcelImporter.GetColumnNamesAsync(path, useHeaderRow, sheetName, startCell, cancellationToken).ConfigureAwait(false),
329-
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(path, useHeaderRow, configuration as Csv.CsvConfiguration, cancellationToken).ConfigureAwait(false),
334+
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(path, useHeaderRow, configuration as NewCsvConfiguration, cancellationToken).ConfigureAwait(false),
330335
_ => throw new InvalidDataException($"Excel type {type} is not a valid Excel type")
331336
};
332337
}
@@ -338,7 +343,7 @@ public static async Task<ICollection<string>> GetColumnsAsync(this Stream stream
338343
return type switch
339344
{
340345
ExcelType.XLSX => await ExcelImporter.GetColumnNamesAsync(stream, useHeaderRow, sheetName, startCell, leaveOpen: true, cancellationToken).ConfigureAwait(false),
341-
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
346+
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(stream, useHeaderRow, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
342347
_ => throw new InvalidDataException($"Excel type {type} is not a valid Excel type")
343348
};
344349
}

0 commit comments

Comments
 (0)