Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void SetUp()
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

_exporter = MiniExcel.Exporters.GetOpenXmlExporter();
_exporter = MiniExcelV2.Exporters.GetOpenXmlExporter();

var simpleRegistry = new MappingRegistry();
simpleRegistry.Configure<DemoDto>(config =>
Expand All @@ -40,7 +40,7 @@ public void SetUp()
config.Property(x => x.Column9).ToCell("I1");
config.Property(x => x.Column10).ToCell("J1");
});
_simpleMappingExporter = MiniExcel.Exporters.GetMappingExporter(simpleRegistry);
_simpleMappingExporter = MiniExcelV2.Exporters.GetMappingExporter(simpleRegistry);
}

[Benchmark(Description = "MiniExcel Create Xlsx")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void SetUp()
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

_importer = MiniExcel.Importers.GetOpenXmlImporter();
_importer = MiniExcelV2.Importers.GetOpenXmlImporter();

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

[Benchmark(Description = "MiniExcel QueryFirst")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public class Employee
[GlobalSetup]
public void Setup()
{
_templater = MiniExcel.Templaters.GetOpenXmlTemplater();
_exporter = MiniExcel.Exporters.GetOpenXmlExporter();
_templater = MiniExcelV2.Templaters.GetOpenXmlTemplater();
_exporter = MiniExcelV2.Exporters.GetOpenXmlExporter();

var registry = new MappingRegistry();
registry.Configure<Employee>(config =>
{
config.Property(x => x.Name).ToCell("A2");
config.Property(x => x.Department).ToCell("B2");
});
_mappingTemplater = MiniExcel.Templaters.GetMappingTemplater(registry);
_mappingTemplater = MiniExcelV2.Templaters.GetMappingTemplater(registry);
}

[Benchmark(Description = "MiniExcel Fill Template")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class XlsxAsyncBenchmark : BenchmarkBase
[GlobalSetup]
public void Setup()
{
_exporter = MiniExcel.Exporters.GetOpenXmlExporter();
_templater = MiniExcel.Templaters.GetOpenXmlTemplater();
_exporter = MiniExcelV2.Exporters.GetOpenXmlExporter();
_templater = MiniExcelV2.Templaters.GetOpenXmlTemplater();
}

[Benchmark(Description = "MiniExcel Create Xlsx Async")]
Expand Down
11 changes: 0 additions & 11 deletions src/MiniExcel.Core/MiniExcel.cs

This file was deleted.

19 changes: 19 additions & 0 deletions src/MiniExcel.Core/MiniExcelV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using MiniExcelLib.Core;

// ReSharper disable once CheckNamespace
namespace MiniExcelLib;

public static class MiniExcelV2
{
public static readonly MiniExcelExporterProvider Exporters = new();
public static readonly MiniExcelImporterProvider Importers = new();
public static readonly MiniExcelTemplaterProvider Templaters = new();
}

[Obsolete("This class will be removed in the full release, use MiniExcelV2 instead.", true)]
public static class MiniExcel
{
public static readonly MiniExcelExporterProvider Exporters = new();
public static readonly MiniExcelImporterProvider Importers = new();
public static readonly MiniExcelTemplaterProvider Templaters = new();
}
43 changes: 24 additions & 19 deletions src/MiniExcel/MiniExcel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@
using MiniExcelLib.OpenXml.Picture;
using Zomp.SyncMethodGenerator;

using NewMiniExcel = MiniExcelLib.MiniExcel;
using NewOpenXmlConfiguration = MiniExcelLib.OpenXml.OpenXmlConfiguration;
using NewCsvConfiguration = MiniExcelLib.Csv.CsvConfiguration;
using MiniExcelDataReader = MiniExcelLib.Core.MiniExcelDataReaderBase;

// ReSharper disable once CheckNamespace
namespace MiniExcelLibs;

/// <summary>
/// This class is a facade containing the methods' signatures from the V1 API, preserved for backwards compatibility.
/// We encourage the users to take advantage of the idiomatic <see cref="MiniExcelV2"/> class instead
/// for a compartimentalized, richer and more flexible API.
Comment thread
michelebastione marked this conversation as resolved.
Resolved
/// </summary>
public static partial class MiniExcel
{
private static readonly OpenXmlExporter ExcelExporter = NewMiniExcel.Exporters.GetOpenXmlExporter();
private static readonly OpenXmlImporter ExcelImporter = NewMiniExcel.Importers.GetOpenXmlImporter();
private static readonly OpenXmlTemplater ExcelTemplater = NewMiniExcel.Templaters.GetOpenXmlTemplater();
private static readonly OpenXmlExporter ExcelExporter = MiniExcelV2.Exporters.GetOpenXmlExporter();
private static readonly OpenXmlImporter ExcelImporter = MiniExcelV2.Importers.GetOpenXmlImporter();
private static readonly OpenXmlTemplater ExcelTemplater = MiniExcelV2.Templaters.GetOpenXmlTemplater();

private static readonly CsvExporter CsvExporter = NewMiniExcel.Exporters.GetCsvExporter();
private static readonly CsvImporter CsvImporter = NewMiniExcel.Importers.GetCsvImporter();
private static readonly CsvExporter CsvExporter = MiniExcelV2.Exporters.GetCsvExporter();
private static readonly CsvImporter CsvImporter = MiniExcelV2.Importers.GetCsvImporter();


[CreateSyncVersion]
Expand Down Expand Up @@ -62,7 +67,7 @@ public static async Task<int> InsertAsync(string path, object value, string shee
return type switch
{
ExcelType.XLSX => await ExcelExporter.InsertSheetAsync(path, value, sheetName, printHeader, overwriteSheet, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvExporter.AppendAsync(path, value, printHeader, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvExporter.AppendAsync(path, value, printHeader, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -76,7 +81,7 @@ public static async Task<int> InsertAsync(this Stream stream, object value, stri
return type switch
{
ExcelType.XLSX => await ExcelExporter.InsertSheetAsync(stream, value, sheetName, printHeader, overwriteSheet, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvExporter.AppendAsync(stream, value, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvExporter.AppendAsync(stream, value, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -90,7 +95,7 @@ public static async Task<int[]> SaveAsAsync(string path, object value, bool prin
return type switch
{
ExcelType.XLSX => await ExcelExporter.ExportAsync(path, value, printHeader, sheetName, overwriteFile, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => [await CsvExporter.ExportAsync(path, value, printHeader, overwriteFile, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
ExcelType.CSV => [await CsvExporter.ExportAsync(path, value, printHeader, overwriteFile, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -104,7 +109,7 @@ public static async Task<int[]> SaveAsAsync(this Stream stream, object value, bo
return type switch
{
ExcelType.XLSX => await ExcelExporter.ExportAsync(stream, value, printHeader, sheetName, configuration as NewOpenXmlConfiguration, progress, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => [await CsvExporter.ExportAsync(stream, value, printHeader, configuration as Csv.CsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
ExcelType.CSV => [await CsvExporter.ExportAsync(stream, value, printHeader, configuration as NewCsvConfiguration, progress, cancellationToken).ConfigureAwait(false)],
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -119,7 +124,7 @@ public static async Task<int[]> SaveAsAsync(this Stream stream, object value, bo
return type switch
{
ExcelType.XLSX => ExcelImporter.QueryAsync<T>(path, sheetName, startCell, !hasHeader, configuration as NewOpenXmlConfiguration, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync<T>(path, !hasHeader, configuration as Csv.CsvConfiguration, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync<T>(path, !hasHeader, configuration as NewCsvConfiguration, cancellationToken),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -134,7 +139,7 @@ public static async Task<int[]> SaveAsAsync(this Stream stream, object value, bo
return type switch
{
ExcelType.XLSX => ExcelImporter.QueryAsync<T>(stream, sheetName, startCell, !hasHeader, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync<T>(stream, !hasHeader, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync<T>(stream, !hasHeader, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -146,7 +151,7 @@ public static IAsyncEnumerable<dynamic> QueryAsync(string path, bool useHeaderRo
return type switch
{
ExcelType.XLSX => ExcelImporter.QueryAsync(path, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync(path, useHeaderRow, configuration as Csv.CsvConfiguration, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync(path, useHeaderRow, configuration as NewCsvConfiguration, cancellationToken),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -158,7 +163,7 @@ public static IAsyncEnumerable<dynamic> QueryAsync(this Stream stream, bool useH
return type switch
{
ExcelType.XLSX => ExcelImporter.QueryAsync(stream, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration,leaveOpen: true, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as NewCsvConfiguration,leaveOpen: true, cancellationToken),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand Down Expand Up @@ -191,7 +196,7 @@ public static IAsyncEnumerable<dynamic> QueryRangeAsync(this Stream stream, bool
return type switch
{
ExcelType.XLSX => ExcelImporter.QueryRangeAsync(stream, useHeaderRow, sheetName, startCell, endCell, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken),
ExcelType.CSV => CsvImporter.QueryAsync(stream, useHeaderRow, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand Down Expand Up @@ -285,7 +290,7 @@ public static async Task<DataTable> QueryAsDataTableAsync(string path, bool useH
return type switch
{
ExcelType.XLSX => await ExcelImporter.QueryAsDataTableAsync(path, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(path, useHeaderRow, configuration as Csv.CsvConfiguration, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(path, useHeaderRow, configuration as NewCsvConfiguration, cancellationToken).ConfigureAwait(false),
_ => throw new InvalidDataException($"Type {type} is not a valid Excel type")
};
}
Expand All @@ -298,7 +303,7 @@ public static async Task<DataTable> QueryAsDataTableAsync(this Stream stream, bo
return type switch
{
ExcelType.XLSX => await ExcelImporter.QueryAsDataTableAsync(stream, useHeaderRow, sheetName, startCell, configuration as NewOpenXmlConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.QueryAsDataTableAsync(stream, useHeaderRow, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
_ => throw new InvalidDataException($"Excel type {type} is not a valid Excel type")
};
}
Expand Down Expand Up @@ -326,7 +331,7 @@ public static async Task<ICollection<string>> GetColumnsAsync(string path, bool
return type switch
{
ExcelType.XLSX => await ExcelImporter.GetColumnNamesAsync(path, useHeaderRow, sheetName, startCell, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(path, useHeaderRow, configuration as Csv.CsvConfiguration, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(path, useHeaderRow, configuration as NewCsvConfiguration, cancellationToken).ConfigureAwait(false),
_ => throw new InvalidDataException($"Excel type {type} is not a valid Excel type")
};
}
Expand All @@ -338,7 +343,7 @@ public static async Task<ICollection<string>> GetColumnsAsync(this Stream stream
return type switch
{
ExcelType.XLSX => await ExcelImporter.GetColumnNamesAsync(stream, useHeaderRow, sheetName, startCell, leaveOpen: true, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(stream, useHeaderRow, configuration as Csv.CsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
ExcelType.CSV => await CsvImporter.GetColumnNamesAsync(stream, useHeaderRow, configuration as NewCsvConfiguration, leaveOpen: true, cancellationToken).ConfigureAwait(false),
_ => throw new InvalidDataException($"Excel type {type} is not a valid Excel type")
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/MiniExcel/MiniExcelConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public static async Task ConvertCsvToXlsxAsync(string csvPath, string xlsxPath,
[CreateSyncVersion]
public static async Task ConvertCsvToXlsxAsync(Stream csvStream, Stream xlsxStream, bool csvHasHeader = false, CancellationToken cancellationToken = default)
{
var value = MiniExcel.Importers.GetCsvImporter()
var value = MiniExcelV2.Importers.GetCsvImporter()
.QueryAsync(csvStream, hasHeaderRow: csvHasHeader, leaveOpen: true, cancellationToken: cancellationToken)
.ConfigureAwait(false);

await MiniExcel.Exporters.GetOpenXmlExporter()
await MiniExcelV2.Exporters.GetOpenXmlExporter()
.ExportAsync(xlsxStream, value, printHeader: csvHasHeader, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Expand Down Expand Up @@ -105,11 +105,11 @@ public static async Task ConvertXlsxToCsvAsync(string xlsxPath, string csvPath,
[CreateSyncVersion]
public static async Task ConvertXlsxToCsvAsync(Stream xlsxStream, Stream csvStream, bool xlsxHasHeader = true, CancellationToken cancellationToken = default)
{
var value = MiniExcel.Importers.GetOpenXmlImporter()
var value = MiniExcelV2.Importers.GetOpenXmlImporter()
.QueryAsync(xlsxStream, hasHeaderRow: xlsxHasHeader, leaveOpen: true, cancellationToken: cancellationToken)
.ConfigureAwait(false);

await MiniExcel.Exporters.GetCsvExporter()
await MiniExcelV2.Exporters.GetCsvExporter()
.ExportAsync(csvStream, value, printHeader: xlsxHasHeader, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace MiniExcelLib.Csv.Tests.DataReader;

public class CsvDataReaderAsyncTests
{
private readonly CsvImporter _csvImporter = MiniExcel.Importers.GetCsvImporter();
private readonly CsvImporter _csvImporter = MiniExcelV2.Importers.GetCsvImporter();

[Fact]
public async Task GetDataReader_WithSimpleData_ReturnsValidDataReader()
Expand Down
2 changes: 1 addition & 1 deletion tests/MiniExcel.Csv.Tests/DataReader/CsvDataReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace MiniExcelLib.Csv.Tests.DataReader;

public class CsvDataReaderTests
{
private readonly CsvImporter _csvImporter = MiniExcel.Importers.GetCsvImporter();
private readonly CsvImporter _csvImporter = MiniExcelV2.Importers.GetCsvImporter();

[Fact]
public void GetDataReader_WithSimpleData_ReturnsValidDataReader()
Expand Down
2 changes: 1 addition & 1 deletion tests/MiniExcel.Csv.Tests/Issues/GiteeIssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace MiniExcelLib.Csv.Tests.Issues;

public class GiteeIssuesTests
{
private readonly CsvExporter _csvExporter = MiniExcel.Exporters.GetCsvExporter();
private readonly CsvExporter _csvExporter = MiniExcelV2.Exporters.GetCsvExporter();

// https://gitee.com/dotnetchina/MiniExcel/issues/I4X92G
[Fact]
Expand Down
8 changes: 4 additions & 4 deletions tests/MiniExcel.Csv.Tests/Issues/GithubIssuesAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class GithubIssuesAsyncTests
{
private readonly CsvExporter _csvExporter = MiniExcel.Exporters.GetCsvExporter();
private readonly CsvImporter _csvImporter = MiniExcel.Importers.GetCsvImporter();
private readonly CsvExporter _csvExporter = MiniExcelV2.Exporters.GetCsvExporter();
private readonly CsvImporter _csvImporter = MiniExcelV2.Importers.GetCsvImporter();

// Support Enum Mapping
[Fact]
Expand Down Expand Up @@ -31,11 +31,11 @@ public async Task Issue89()
Assert.Equal(Issue89Dto.WorkState.Leave, rows1[2].State);

using var outputPath = AutoDeletingPath.Create();
var rowsWritten = await MiniExcel.Exporters.GetOpenXmlExporter().ExportAsync(outputPath.ToString(), rows1);
var rowsWritten = await MiniExcelV2.Exporters.GetOpenXmlExporter().ExportAsync(outputPath.ToString(), rows1);
Assert.Single(rowsWritten);
Assert.Equal(3, rowsWritten[0]);

var rows2 = await MiniExcel.Importers.GetOpenXmlImporter().QueryAsync<Issue89Dto>(outputPath.ToString()).ToListAsync();
var rows2 = await MiniExcelV2.Importers.GetOpenXmlImporter().QueryAsync<Issue89Dto>(outputPath.ToString()).ToListAsync();
Assert.Equal(Issue89Dto.WorkState.OnDuty, rows2[0].State);
Assert.Equal(Issue89Dto.WorkState.Fired, rows2[1].State);
Assert.Equal(Issue89Dto.WorkState.Leave, rows2[2].State);
Expand Down
Loading
Loading