Skip to content
Merged
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
8 changes: 5 additions & 3 deletions README-V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Check what we are planning for future versions [here](https://github.com/mini-so

The code for the benchmarks can be found in [MiniExcel.Benchmarks](benchmarks/MiniExcel.Benchmarks/Program.cs).

The file used to test performance is [**Test1,000,000x10.xlsx**](benchmarks/MiniExcel.Benchmarks/Test1%2C000%2C000x10.xlsx), a 32MB document containing 1,000,000 rows * 10 columns whose cells are filled with the string "HelloWorld".
The main file used to test performance is [**Test100,000x10.xlsx**](benchmarks/MiniExcel.Benchmarks/Test1%2C000%2C000x10.xlsx), a document containing 100,000 rows * 10 columns whose cells are filled with unique strings.

To run all the benchmarks use:

Expand Down Expand Up @@ -1606,12 +1606,12 @@ There is support for reading one cell at a time using a custom `IDataReader`:

```csharp
var importer = MiniExcel.Importers.GetOpenXmlImporter();
using var reader = importer.GetDataReader(path, useHeaderRow: true);
using OpenXmlDataReader reader = importer.GetDataReader(path, hasHeaderRow: true);

// or

var importer = MiniExcel.Importers.GetCsvImporter();
using var reader = importer.GetDataReader(path, useHeaderRow: true);
using CsvDataReader reader = importer.GetDataReader(path, hasHeaderRow: true);


while (reader.Read())
Expand All @@ -1622,6 +1622,8 @@ while (reader.Read())
}
}
```
When not providing a specific worksheet name, all sheets will be available sequentially by calling the `NextResult` method on the `OpenXmlDataReader`.
Calling the `NextResult` method on the `CsvDataReader` will always raise a `NotSupportedException` instead.


#### Add records
Expand Down
3 changes: 2 additions & 1 deletion V2-Upgrade-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ so the return type for `OpenXmlImporter.QueryAsync` is `IAsyncEnumerable<T>` ins
- When applying a template, unlike version 1.x, the flag for overwriting an already existing file must be provided explicitly.
- `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.
- `useHeaderRow` parameter in multiple `OpenXmlImporter` methods has been renamed to `hasHeaderRow` for making its usage clearer.
- `CsvExporter.Export` API methods, not being required to return the same type of `OpenXmlExporter.Export`, now return `int` instead of `int[]`.
- `CsvExporter.Export` API methods, not being required to return the same type of `OpenXmlExporter.Export`, now return `int` instead of `int[]`.
- 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.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using MiniExcelLib.Benchmarks.Utils;
using MiniExcelLib.Core;
using MiniExcelLib.OpenXml;
using MiniExcelLib.OpenXml.FluentMapping;
using MiniExcelLib.OpenXml.FluentMapping.Api;
Expand All @@ -16,8 +15,8 @@ namespace MiniExcelLib.Benchmarks.BenchmarkSections;

public class CreateExcelBenchmark : BenchmarkBase
{
private OpenXmlExporter _exporter;
private MappingExporter _simpleMappingExporter;
private OpenXmlExporter _exporter = null!;
private MappingExporter _simpleMappingExporter = null!;

[GlobalSetup]
public void SetUp()
Expand Down Expand Up @@ -117,13 +116,13 @@ public void OpenXmlSdkCreateByDomModeTest()
using var spreadsheetDocument = SpreadsheetDocument.Create(path.FilePath, SpreadsheetDocumentType.Workbook);
// By default, AutoSave = true, Editable = true, and Type = xlsx.

WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
var workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();

WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());

Sheets sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());
var sheets = spreadsheetDocument.WorkbookPart!.Workbook!.AppendChild(new Sheets());

sheets.Append(new Sheet
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using ExcelDataReader;
using MiniExcelLib.Core;
using MiniExcelLib.OpenXml;
using MiniExcelLib.OpenXml.FluentMapping;
using MiniExcelLib.OpenXml.FluentMapping.Api;
Expand All @@ -15,8 +14,8 @@ namespace MiniExcelLib.Benchmarks.BenchmarkSections;

public class QueryExcelBenchmark : BenchmarkBase
{
private OpenXmlImporter _importer;
private MappingImporter _mappingImporter;
private OpenXmlImporter _importer = null!;
private MappingImporter _mappingImporter = null!;

[GlobalSetup]
public void SetUp()
Expand Down Expand Up @@ -55,7 +54,7 @@ public void MiniExcel_Query()
{
foreach (var row in _importer.Query(FilePath))
{
var value = row;
_ = row;
}
}

Expand All @@ -70,7 +69,7 @@ public void MiniExcel_Query_Mapping()
{
foreach (var row in _mappingImporter.Query<DemoDto>(FilePath))
{
var value = row;
_ = row;
}
}

Expand All @@ -83,7 +82,7 @@ public void ExcelDataReader_QueryFirst_Test()
reader.Read();
for (var i = 0; i < reader.FieldCount; i++)
{
var value = reader.GetValue(i);
_ = reader.GetValue(i);
}
}

Expand All @@ -97,7 +96,7 @@ public void ExcelDataReader_Query_Test()
{
for (var i = 0; i < reader.FieldCount; i++)
{
var value = reader.GetValue(i);
_ = reader.GetValue(i);
}
}
}
Expand All @@ -122,7 +121,7 @@ public void Epplus_Query_Test()
{
for (var col = start.Column; col <= end.Column; col++)
{
object cellValue = workSheet.Cells[row, col].Text;
_ = workSheet.Cells[row, col].Text;
}
}
}
Expand Down Expand Up @@ -162,11 +161,12 @@ public void NPOI_Query_Test()
{
for (var j = row.FirstCellNum; j <= row.LastCellNum; j++)
{
var cellValue = row.GetCell(j)?.StringCellValue;
_ = row.GetCell(j)?.StringCellValue;
}
}
}
}

[Benchmark(Description = "OpenXmlSDK QueryFirst")]
public void OpenXmlSDK_QueryFirst_Test()
{
Expand All @@ -175,8 +175,9 @@ public void OpenXmlSDK_QueryFirst_Test()
var workbookPart = spreadsheetDocument.WorkbookPart;
var worksheetPart = workbookPart!.WorksheetParts.First();

var sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
var sheetData = worksheetPart.Worksheet!.Elements<SheetData>().First();
var firstRow = sheetData.Elements<Row>().First();
_ = firstRow;
}

[Benchmark(Description = "OpenXmlSDK Query")]
Expand All @@ -187,10 +188,10 @@ public void OpenXmlSDK_Query_Test()
var workbookPart = spreadsheetDocument.WorkbookPart;
var worksheetPart = workbookPart!.WorksheetParts.First();

var sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
var sheetData = worksheetPart.Worksheet!.Elements<SheetData>().First();
foreach(var row in sheetData.Elements<Row>())
{
var cellValue = row;
_ = row;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BenchmarkDotNet.Attributes;
using ClosedXML.Report;
using MiniExcelLib.Benchmarks.Utils;
using MiniExcelLib.Core;
using MiniExcelLib.OpenXml;
using MiniExcelLib.OpenXml.FluentMapping;
using MiniExcelLib.OpenXml.FluentMapping.Api;
Expand All @@ -10,9 +9,9 @@ namespace MiniExcelLib.Benchmarks.BenchmarkSections;

public class TemplateExcelBenchmark : BenchmarkBase
{
private OpenXmlTemplater _templater;
private MappingTemplater _mappingTemplater;
private OpenXmlExporter _exporter;
private OpenXmlTemplater _templater = null!;
private MappingTemplater _mappingTemplater = null!;
private OpenXmlExporter _exporter = null!;

public class Employee
{
Expand Down Expand Up @@ -44,7 +43,7 @@ public void MiniExcel_Template_Generate_Test()
var value = new
{
employees = Enumerable.Range(1, RowCount)
.Select(s => new
.Select(_ => new
{
name = "Jack",
department = "HR"
Expand Down Expand Up @@ -90,7 +89,7 @@ public void MiniExcel_Mapping_Template_Generate_Test()

using var outputPath = AutoDeletingPath.Create();
var employees = Enumerable.Range(1, RowCount)
.Select(s => new Employee
.Select(_ => new Employee
{
Name = "Jack",
Department = "HR"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using BenchmarkDotNet.Attributes;
using MiniExcelLib.Benchmarks.Utils;
using MiniExcelLib.Core;
using MiniExcelLib.OpenXml;

namespace MiniExcelLib.Benchmarks.BenchmarkSections;

public class XlsxAsyncBenchmark : BenchmarkBase
{
private OpenXmlExporter _exporter;
private OpenXmlTemplater _templater;
private OpenXmlExporter _exporter = null!;
private OpenXmlTemplater _templater = null!;

[GlobalSetup]
public void Setup()
Expand All @@ -35,7 +34,7 @@ public async Task MiniExcel_Template_Generate_Async_Test()
var value = new
{
employees = Enumerable.Range(1, RowCount)
.Select(s => new
.Select(_ => new
{
name = "Jack",
department = "HR"
Expand Down
3 changes: 2 additions & 1 deletion src/MiniExcel.Core/Abstractions/IMiniExcelDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public interface IMiniExcelDataReader : IDataReader, IAsyncDisposable
{
Task CloseAsync();
Task<bool> ReadAsync(CancellationToken cancellationToken = default);
}
Task<bool> NextResultAsync(CancellationToken cancellationToken = default);
}
2 changes: 1 addition & 1 deletion src/MiniExcel.Core/Abstractions/IMiniExcelReader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace MiniExcelLib.Core.Abstractions;

public partial interface IMiniExcelReader : IDisposable
public partial interface IMiniExcelReader : IDisposable, IAsyncDisposable
{
[CreateSyncVersion]
IAsyncEnumerable<IDictionary<string, object?>> QueryAsync(bool hasHeaderRow, string? sheetName, string startCell, CancellationToken cancellationToken = default);
Expand Down
6 changes: 3 additions & 3 deletions src/MiniExcel.Core/Exceptions/ValueNotAssignableException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace MiniExcelLib.Core.Exceptions;

public class ValueNotAssignableException(string columnName, int row, object value, Type columnType, string message)
public class ValueNotAssignableException(string columnName, int row, object? value, Type columnType, string message)
: InvalidCastException(message)
{
public string ColumnName { get; set; } = columnName;
public int Row { get; set; } = row;
public object Value { get; set; } = value;
public object? Value { get; set; } = value;
public Type ColumnType { get; set; } = columnType;
}
}
7 changes: 5 additions & 2 deletions src/MiniExcel.Core/MiniExcel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace MiniExcelLib.Core;
using MiniExcelLib.Core;

// ReSharper disable once CheckNamespace
namespace MiniExcelLib;

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