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
Binary file added samples/xlsx/Issue888_DataWithFrame.xlsx
Binary file not shown.
8 changes: 4 additions & 4 deletions src/MiniExcel.Core/OpenXml/OpenXmlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ internal static async Task<OpenXmlReader> CreateAsync(Stream stream, IMiniExcelC

if (rowIndex < startRowIndex)
{
await XmlReaderHelper.ReadFirstContentAsync(reader, cancellationToken)
.ConfigureAwait(false);
await XmlReaderHelper.SkipToNextSameLevelDomAsync(reader, cancellationToken)
.ConfigureAwait(false);
if (await XmlReaderHelper.ReadFirstContentAsync(reader, cancellationToken).ConfigureAwait(false))
{
await XmlReaderHelper.SkipToNextSameLevelDomAsync(reader, cancellationToken).ConfigureAwait(false);
}
continue;
}

Expand Down
14 changes: 5 additions & 9 deletions tests/MiniExcel.Core.Tests/MiniExcelIssueAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,10 +1329,8 @@ public async Task Issue153()
public void Issue137()
{
const string path = "../../../../../samples/xlsx/TestIssue137.xlsx";
var config = new OpenXmlConfiguration { Culture = new CultureInfo("it")};

{
var q = _excelImporter.QueryAsync(path, configuration: config).ToBlockingEnumerable();
var q = _excelImporter.QueryAsync(path).ToBlockingEnumerable();
var rows = q.ToList();
var first = rows[0] as IDictionary<string, object>; // https://user-images.githubusercontent.com/12729184/113266322-ba06e400-9307-11eb-9521-d36abfda75cc.png
Assert.Equal(["A", "B", "C", "D", "E", "F", "G", "H"], first?.Keys.ToArray());
Expand Down Expand Up @@ -1368,7 +1366,7 @@ public void Issue137()

// dynamic query with head
{
var q = _excelImporter.QueryAsync(path, true, configuration: config).ToBlockingEnumerable();
var q = _excelImporter.QueryAsync(path, true).ToBlockingEnumerable();
var rows = q.ToList();
var first = rows[0] as IDictionary<string, object>; // https://user-images.githubusercontent.com/12729184/113266322-ba06e400-9307-11eb-9521-d36abfda75cc.png
Assert.Equal(["比例", "商品", "滿倉口數", "0", "1為港幣 0為台幣"], first?.Keys.ToArray());
Expand All @@ -1390,7 +1388,7 @@ public void Issue137()
}

{
var q = _excelImporter.QueryAsync<Issue137ExcelRow>(path, configuration: config).ToBlockingEnumerable();
var q = _excelImporter.QueryAsync<Issue137ExcelRow>(path).ToBlockingEnumerable();
var rows = q.ToList();
Assert.Equal(10, rows.Count);

Expand Down Expand Up @@ -1423,10 +1421,8 @@ private class Issue137ExcelRow
public void Issue138()
{
const string path = "../../../../../samples/xlsx/TestIssue138.xlsx";
var config = new OpenXmlConfiguration { Culture = new CultureInfo("it") };

{
var q = _excelImporter.QueryAsync(path, true, configuration: config).ToBlockingEnumerable();
var q = _excelImporter.QueryAsync(path, true).ToBlockingEnumerable();
var rows = q.ToList();
Assert.Equal(6, rows.Count);

Expand All @@ -1452,7 +1448,7 @@ public void Issue138()
}
{

var q = _excelImporter.QueryAsync<Issue138ExcelRow>(path, configuration: config).ToBlockingEnumerable();
var q = _excelImporter.QueryAsync<Issue138ExcelRow>(path).ToBlockingEnumerable();
var rows = q.ToList();
Assert.Equal(6, rows.Count);
Assert.Equal(new DateTime(2021, 3, 1), rows[0].Date);
Expand Down
48 changes: 35 additions & 13 deletions tests/MiniExcel.Core.Tests/MiniExcelIssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2527,10 +2527,8 @@ public void Issue153()
public void Issue137()
{
const string path = "../../../../../samples/xlsx/TestIssue137.xlsx";
var config = new OpenXmlConfiguration { Culture = new CultureInfo("it") };

{
var rows = _excelImporter.Query(path, configuration: config).ToList();
var rows = _excelImporter.Query(path).ToList();
var first = rows[0] as IDictionary<string, object>; // https://user-images.githubusercontent.com/12729184/113266322-ba06e400-9307-11eb-9521-d36abfda75cc.png
Assert.Equal(["A", "B", "C", "D", "E", "F", "G", "H"], first?.Keys.ToArray());
Assert.Equal(11, rows.Count);
Expand Down Expand Up @@ -2564,7 +2562,7 @@ public void Issue137()

// dynamic query with head
{
var rows = _excelImporter.Query(path, true, configuration: config).ToList();
var rows = _excelImporter.Query(path, true).ToList();
var first = rows[0] as IDictionary<string, object>; //![image](https://user-images.githubusercontent.com/12729184/113266322-ba06e400-9307-11eb-9521-d36abfda75cc.png)
Assert.Equal(["比例", "商品", "滿倉口數", "0", "1為港幣 0為台幣"], first?.Keys.ToArray());
Assert.Equal(10, rows.Count);
Expand All @@ -2584,7 +2582,7 @@ public void Issue137()
}

{
var rows = _excelImporter.Query<Issue137ExcelRow>(path, configuration: config).ToList();
var rows = _excelImporter.Query<Issue137ExcelRow>(path).ToList();
Assert.Equal(10, rows.Count);
{
var row = rows[0];
Expand Down Expand Up @@ -2615,11 +2613,8 @@ private class Issue137ExcelRow
public void Issue138()
{
const string path = "../../../../../samples/xlsx/TestIssue138.xlsx";
var config = new OpenXmlConfiguration { Culture = new CultureInfo("zh") };
config.Culture.NumberFormat.NumberDecimalSeparator = ",";

{
var rows = _excelImporter.Query(path, true, configuration: config).ToList();
var rows = _excelImporter.Query(path, true).ToList();
Assert.Equal(6, rows.Count);

foreach (var index in new[] { 0, 2, 5 })
Expand All @@ -2644,7 +2639,7 @@ public void Issue138()
}
{

var rows = _excelImporter.Query<Issue138ExcelRow>(path, configuration: config).ToList();
var rows = _excelImporter.Query<Issue138ExcelRow>(path).ToList();
Assert.Equal(6, rows.Count);
Assert.Equal(new DateTime(2021, 3, 1), rows[0].Date);

Expand Down Expand Up @@ -2774,10 +2769,11 @@ public void Issue422()
new { Row1 = "1", Row2 = "2" },
new { Row1 = "3", Row2 = "4" }
};

var enumerableWithCount = new Issue422Enumerable(items);

using var path = AutoDeletingPath.Create();
_excelExporter.Export(path.ToString(), enumerableWithCount);
_excelExporter.Export(path.ToString(), enumerableWithCount);

Assert.Equal(1, enumerableWithCount.GetEnumeratorCount);
}

Expand Down Expand Up @@ -2855,7 +2851,7 @@ WITH test('Id', 'Name') AS (
using var reader = cmd.ExecuteReader();

using var path = AutoDeletingPath.Create();
_excelExporter.Export(path.FilePath, reader, configuration: excelconfig, overwriteFile: true);
_excelExporter.Export(path.FilePath, reader, configuration: excelconfig, overwriteFile: true);

var rows = _excelImporter.Query(path.FilePath).ToList();
Assert.All(rows, x => Assert.Single(x));
Expand Down Expand Up @@ -3765,4 +3761,30 @@ public void TestIssue881()
_ = _excelImporter.Query<Issues409_881>(PathHelper.GetFile("xlsx/TestIssue881.xlsx")).ToList();
});
}

private record ExcelDataRow(string Key, string Value)
{
public ExcelDataRow() : this("", "") { }
}

/// <summary>
/// https://github.com/mini-software/MiniExcel/issues/888
/// </summary>
[Fact]
public void TestIssue888_ShouldIgnoreFrame()
{
var xlsxPath = PathHelper.GetFile("xlsx/Issue888_DataWithFrame.xlsx");
ExcelDataRow[] dataInSheet =
[
new("Key1", "Value1"),
new("Key2", "Value2")
];

// Act
using var stream = File.OpenRead(xlsxPath);
var dataRead = _excelImporter.Query<ExcelDataRow>(stream, startCell: "A2").ToArray();

Assert.Equal(dataInSheet, dataRead);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ public async Task TestIEnumerableType()
};
await _excelTemplater.ApplyTemplateAsync(path.ToString(), templatePath, value);

var config = new OpenXmlConfiguration { Culture = new CultureInfo("it") };

var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString(), configuration: config).ToList();
var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString()).ToList();
Assert.Equal(poco.@string, rows[0].@string);
Assert.Equal(poco.@int, rows[0].@int);
Assert.Equal(poco.@double, rows[0].@double);
Expand Down Expand Up @@ -409,9 +407,7 @@ public async Task TestTemplateTypeMapping()
};
await _excelTemplater.ApplyTemplateAsync(path.ToString(), templatePath, value);

var config = new OpenXmlConfiguration { Culture = new CultureInfo("it") };

var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString(), configuration: config).ToList();
var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString()).ToList();
Assert.Equal(value.@string, rows[0].@string);
Assert.Equal(value.@int, rows[0].@int);
Assert.Equal(value.@double, rows[0].@double);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,7 @@ public void TestIEnumerableType()
};
_excelTemplater.ApplyTemplate(path.ToString(), templatePath, value);

var config = new OpenXmlConfiguration { Culture = new CultureInfo("it") };

var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString(), configuration: config).ToList();
var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString()).ToList();
Assert.Equal(poco.@string, rows[0].@string);
Assert.Equal(poco.@int, rows[0].@int);
Assert.Equal(poco.@double, rows[0].@double);
Expand Down Expand Up @@ -589,9 +587,7 @@ public void TestTemplateTypeMapping()
};
_excelTemplater.ApplyTemplate(path.ToString(), templatePath, value);

var config = new OpenXmlConfiguration { Culture = new CultureInfo("it") };

var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString(), configuration: config).ToList();
var rows = _excelImporter.Query<TestIEnumerableTypePoco>(path.ToString()).ToList();
Assert.Equal(value.@string, rows[0].@string);
Assert.Equal(value.@int, rows[0].@int);
Assert.Equal(value.@double, rows[0].@double);
Expand Down
Loading