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
7 changes: 7 additions & 0 deletions src/MiniExcel/MiniExcelDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public override string GetName(int i)
return _keys[i];
}

/// <inheritdoc/>
public override int GetOrdinal(string name)
{
_keys.IndexOf(name);
return _keys.IndexOf(name);
}

/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
Expand Down
71 changes: 51 additions & 20 deletions tests/MiniExcelTests/MiniExcelIssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
};
var path = Path.GetTempPath() + Guid.NewGuid() + ".xlsx";
MiniExcel.SaveAs(path, data);
var rows = MiniExcel.Query(path,true).ToList();
var rows = MiniExcel.Query(path, true).ToList();
{
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
Expand Down Expand Up @@ -373,7 +373,7 @@
var sheets = MiniExcel.GetSheetNames(path);
foreach (var sheetName in sheets)
{
var dt = MiniExcel.QueryAsDataTable(path, useHeaderRow: true, sheetName: sheetName, configuration: config);

Check warning on line 376 in tests/MiniExcelTests/MiniExcelIssueTests.cs

View workflow job for this annotation

GitHub Actions / build

'MiniExcel.QueryAsDataTable(string, bool, string, ExcelType, string, IConfiguration)' is obsolete: 'QueryAsDataTable is not recommended, because it'll load all data into memory.'
}
}

Expand Down Expand Up @@ -1323,7 +1323,7 @@
public void TestIssue298()
{
var path = PathHelper.GetFile("/csv/TestIssue298.csv");
var dt = MiniExcel.QueryAsDataTable(path);

Check warning on line 1326 in tests/MiniExcelTests/MiniExcelIssueTests.cs

View workflow job for this annotation

GitHub Actions / build

'MiniExcel.QueryAsDataTable(string, bool, string, ExcelType, string, IConfiguration)' is obsolete: 'QueryAsDataTable is not recommended, because it'll load all data into memory.'
Assert.Equal(new[] { "ID", "Name", "Age" }, dt.Columns.Cast<DataColumn>().Select(_ => _.ColumnName));
}

Expand Down Expand Up @@ -1656,7 +1656,7 @@
public void TestIssue279()
{
var path = PathHelper.GetFile("/csv/TestHeader.csv");
var dt = MiniExcel.QueryAsDataTable(path, true, null, ExcelType.CSV);

Check warning on line 1659 in tests/MiniExcelTests/MiniExcelIssueTests.cs

View workflow job for this annotation

GitHub Actions / build

'MiniExcel.QueryAsDataTable(string, bool, string, ExcelType, string, IConfiguration)' is obsolete: 'QueryAsDataTable is not recommended, because it'll load all data into memory.'
Assert.Equal("A1", dt.Rows[0]["Column1"]);
Assert.Equal("A2", dt.Rows[1]["Column1"]);
Assert.Equal("B1", dt.Rows[0]["Column2"]);
Expand Down Expand Up @@ -2102,7 +2102,7 @@
public void Issue233()
{
var path = PathHelper.GetFile("xlsx/TestIssue233.xlsx");
var dt = MiniExcel.QueryAsDataTable(path);

Check warning on line 2105 in tests/MiniExcelTests/MiniExcelIssueTests.cs

View workflow job for this annotation

GitHub Actions / build

'MiniExcel.QueryAsDataTable(string, bool, string, ExcelType, string, IConfiguration)' is obsolete: 'QueryAsDataTable is not recommended, because it'll load all data into memory.'
var rows = dt.Rows;

Assert.Equal(0.55, rows[0]["Size"]);
Expand Down Expand Up @@ -2228,7 +2228,7 @@
public void Issue229()
{
var path = PathHelper.GetFile("xlsx/TestIssue229.xlsx");
var dt = MiniExcel.QueryAsDataTable(path);

Check warning on line 2231 in tests/MiniExcelTests/MiniExcelIssueTests.cs

View workflow job for this annotation

GitHub Actions / build

'MiniExcel.QueryAsDataTable(string, bool, string, ExcelType, string, IConfiguration)' is obsolete: 'QueryAsDataTable is not recommended, because it'll load all data into memory.'
foreach (DataColumn column in dt.Columns)
{
var v = dt.Rows[3][column];
Expand Down Expand Up @@ -3536,7 +3536,8 @@
public int D { get; set; }
}

class Issue507V02 {
class Issue507V02
{
public DateTime B { get; set; }
public int D { get; set; }
}
Expand All @@ -3547,7 +3548,7 @@
//Problem with multi-line when using Query func
//https://github.com/mini-software/MiniExcel/issues/507

var path = Path.Combine(Path.GetTempPath(), string.Concat( nameof(MiniExcelIssueTests),"_", nameof(Issue507_1), ".csv" ));
var path = Path.Combine(Path.GetTempPath(), string.Concat(nameof(MiniExcelIssueTests), "_", nameof(Issue507_1), ".csv"));
var values = new Issue507V01[]
{
new() { A = "Github", B = DateTime.Parse("2021-01-01"), C = "abcd", D = 123 },
Expand All @@ -3570,9 +3571,9 @@

// read
var getRowsInfo = MiniExcel.Query<Issue507V01>(path, excelType: ExcelType.CSV, configuration: config).ToArray();

Assert.Equal(values.Length, getRowsInfo.Count());

Assert.Equal("Github", getRowsInfo[0].A);
Assert.Equal("abcd", getRowsInfo[0].C);

Expand All @@ -3587,7 +3588,8 @@
}

[Fact]
public void Issue507_2() {
public void Issue507_2()
{
//Problem with multi-line when using Query func
//https://github.com/mini-software/MiniExcel/issues/507

Expand Down Expand Up @@ -3620,7 +3622,8 @@
}

[Fact]
public void Issue507_3_MismatchedQuoteCsv() {
public void Issue507_3_MismatchedQuoteCsv()
{
//Problem with multi-line when using Query func
//https://github.com/mini-software/MiniExcel/issues/507

Expand All @@ -3633,12 +3636,12 @@
var badCsv = "A,B,C\n\"r1a: no end quote,r1b,r1c";

// create
using var stream = new MemoryStream( Encoding.UTF8.GetBytes( badCsv ) );
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(badCsv));

// read
var getRowsInfo = MiniExcel.Query( stream, excelType: ExcelType.CSV, configuration: config ).ToArray();
var getRowsInfo = MiniExcel.Query(stream, excelType: ExcelType.CSV, configuration: config).ToArray();

Assert.Equal(2, getRowsInfo.Length );
Assert.Equal(2, getRowsInfo.Length);

}

Expand All @@ -3655,8 +3658,8 @@
{
Title = "My Title",
OrderInfo = Enumerable
.Range( 1, 100 )
.Select( x => new
.Range(1, 100)
.Select(x => new
{
Standard = "standard",
RegionName = "region",
Expand All @@ -3682,13 +3685,13 @@
var path = Path.Combine
(
Path.GetTempPath(),
string.Concat( nameof( MiniExcelIssueTests ), "_", nameof( Issue606_1 ), ".xlsx" )
string.Concat(nameof(MiniExcelIssueTests), "_", nameof(Issue606_1), ".xlsx")
);

var templateFileName = @"../../../../../samples/xlsx/TestIssue606_Template.xlsx";


MiniExcel.SaveAsByTemplate( path, Path.GetFullPath( templateFileName ), value );
MiniExcel.SaveAsByTemplate(path, Path.GetFullPath(templateFileName), value);

}

Expand All @@ -3698,7 +3701,8 @@
//https://github.com/mini-software/MiniExcel/issues/632
var values = new List<Dictionary<string, object>>();

foreach ( var item in Enumerable.Range( 1, 100 ) ) {
foreach (var item in Enumerable.Range(1, 100))
{
var dict = new Dictionary<string, object>
{
{ "Id", item },
Expand All @@ -3711,7 +3715,7 @@
{ "Network Usage (Kb/s)", Math.Round( 4503.23422, 1 ) },
{ "Instrument", "QT800050" }
};
values.Add( dict );
values.Add(dict);
}

var config = new OpenXmlConfiguration
Expand All @@ -3728,11 +3732,11 @@

var path = Path.Combine(
Path.GetTempPath(),
string.Concat( nameof( MiniExcelIssueTests ), "_", nameof( Issue632_1 ), ".xlsx" )
string.Concat(nameof(MiniExcelIssueTests), "_", nameof(Issue632_1), ".xlsx")
);
MiniExcel.SaveAs( path, values, excelType: ExcelType.XLSX, configuration: config, overwriteFile: true );

MiniExcel.SaveAs(path, values, excelType: ExcelType.XLSX, configuration: config, overwriteFile: true);

}

private class Issue658TestData
Expand Down Expand Up @@ -3811,5 +3815,32 @@
i++;
}
}

[Fact]
public void Issue_710()
{
var values = new[] { new { Column1 = "MiniExcel", Column2 = 1, Column3 = "Test" } };
using var memoryStream = new MemoryStream();
memoryStream.SaveAs(values, configuration: new OpenXmlConfiguration
{
FastMode = true,
});

memoryStream.Position = 0;

var dataReader = memoryStream.GetReader(useHeaderRow: false);

dataReader.Read();
{
for (int i = 0; i < dataReader.FieldCount; i++)
{
var columnName = dataReader.GetName(i);

var ordinal = dataReader.GetOrdinal(columnName);

Assert.Equal(i, ordinal);
}
}
}
}
}
Loading