add QueryRange test and docs.(#634) (#635)

This commit is contained in:
Jed Samok 2024-07-19 22:04:44 +08:00 committed by GitHub
parent 7ecf0ffe69
commit 9de96abba8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 0 deletions

View File

@ -259,6 +259,10 @@ foreach(IDictionary<string,object> row in MiniExcel.Query(path))
// or
var rows = MiniExcel.Query(path).Cast<IDictionary<string,object>>();
// or Query specified ranges (capitalized)
// A2 represents the second row of column A, C3 represents the third row of column C
// If you don't want to restrict rows, just don't include numbers
var rows = MiniExcel.QueryRange(path, startCell: "A2", endCell: "C3").Cast<IDictionary<string, object>>();
```

View File

@ -267,6 +267,10 @@ foreach(IDictionary<string,object> row in MiniExcel.Query(path))
// or
var rows = MiniExcel.Query(path).Cast<IDictionary<string,object>>();
// or 查询指定范围(要大写才生效哦)
// A2左上角代表A列的第二行C3右下角代表C列的第三行
// 如果你不想限制行,就不要包含数字
var rows = MiniExcel.QueryRange(path, startCell: "A2", endCell: "C3").Cast<IDictionary<string, object>>();
```
#### 9. Query 读 Excel 返回 DataTable

View File

@ -265,6 +265,10 @@ foreach(IDictionary<string,object> row in MiniExcel.Query(path))
// or
var rows = MiniExcel.Query(path).Cast<IDictionary<string,object>>();
// or 査詢指定範圍(要大寫才生效哦)
// A2左上角代表A列的第二行C3右下角代表C列的第三行
// 如果你不想限制行,就不要包含數位
var rows = MiniExcel.QueryRange(path, startCell: "A2", endCell: "C3").Cast<IDictionary<string, object>>();
```

View File

@ -91,6 +91,21 @@
#region range
/// <summary>
/// Extract the given range。 Only uppercase letters are effective。
/// e.g.
/// MiniExcel.QueryRange(path, startCell: "A2", endCell: "C3")
/// A2 represents the second row of column A, C3 represents the third row of column C
/// If you don't want to restrict rows, just don't include numbers
/// </summary>
/// <param name="path"></param>
/// <param name="useHeaderRow"></param>
/// <param name="sheetName"></param>
/// <param name="excelType"></param>
/// <param name="startCell">top left corner</param>
/// <param name="endCell">lower right corner</param>
/// <param name="configuration"></param>
/// <returns></returns>
public static IEnumerable<dynamic> QueryRange(string path, bool useHeaderRow = false, string sheetName = null, ExcelType excelType = ExcelType.UNKNOWN, string startCell = "a1", string endCell = "", IConfiguration configuration = null)
{
using (var stream = FileHelper.OpenSharedRead(path))

View File

@ -166,6 +166,21 @@ namespace MiniExcelLibs.Tests
}
}
[Fact]
public void QueryRangeToIDictionary()
{
var path = @"../../../../../samples/xlsx/TestCenterEmptyRow/TestCenterEmptyRow.xlsx";
// tipsOnly uppercase letters are effective
var rows = MiniExcel.QueryRange(path, startCell: "A2", endCell: "C")
.Cast<IDictionary<string, object>>()
.ToList();
Assert.Equal(5, rows.Count);
Assert.Equal(3, rows[0].Count);
Assert.Equal(2d, rows[1]["B"]);
Assert.Equal(null!, rows[2]["A"]);
}
[Fact()]
public void CenterEmptyRowsQueryTest()
{