mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-11-29 18:38:08 +08:00
add QueryRange test and docs.(#634) (#635)
This commit is contained in:
parent
7ecf0ffe69
commit
9de96abba8
@ -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>>();
|
||||
```
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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>>();
|
||||
```
|
||||
|
||||
|
||||
|
@ -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))
|
||||
|
@ -166,6 +166,21 @@ namespace MiniExcelLibs.Tests
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueryRangeToIDictionary()
|
||||
{
|
||||
var path = @"../../../../../samples/xlsx/TestCenterEmptyRow/TestCenterEmptyRow.xlsx";
|
||||
// tips:Only 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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user