doc add FQA

This commit is contained in:
wei 2021-04-15 12:12:28 +08:00
parent 1be832d8bd
commit 4728be6fe5
4 changed files with 119 additions and 2 deletions

View File

@ -635,6 +635,40 @@ public static IEnumerable<T> Page<T>(IEnumerable<T> en, int pageSize, int page)
### FQA
#### Q: How to Query as DataTable
Note : There will be no advantage *whatsoever* in using MiniExcel for a scenario involving `DataSet` or `DataTable`.
```C#
public static DataTable QueryAsDataTable(string path)
{
var rows = MiniExcel.Query(path, true);
var dt = new DataTable();
var first = true;
foreach (IDictionary<string, object> row in rows)
{
if (first)
{
foreach (var key in row.Keys)
{
var type = row[key]?.GetType() ?? typeof(string);
dt.Columns.Add(key, type);
}
first = false;
}
dt.Rows.Add(row.Values.ToArray());
}
return dt;
}
```
![image-20210415120352604](https://i.loli.net/2021/04/15/TbtP1GLDEgONueK.png)
### Limitations and caveats
- Not support xls and encrypted file now

View File

@ -642,6 +642,40 @@ public static IEnumerable<T> Page<T>(IEnumerable<T> en, int pageSize, int page)
### FQA
#### Q: 如何将查询结果转为 DataTable
提醒 : 不建议使用因为DataTable会将数据`全载入内存`失去MiniExcel低内存消耗功能。
```C#
public static DataTable QueryAsDataTable(string path)
{
var rows = MiniExcel.Query(path, true);
var dt = new DataTable();
var first = true;
foreach (IDictionary<string, object> row in rows)
{
if (first)
{
foreach (var key in row.Keys)
{
var type = row[key]?.GetType() ?? typeof(string);
dt.Columns.Add(key, type);
}
first = false;
}
dt.Rows.Add(row.Values.ToArray());
}
return dt;
}
```
![image-20210415120352604](https://i.loli.net/2021/04/15/TbtP1GLDEgONueK.png)
### 局限与警告
- 目前不支援 xls (97-2003) 或是加密文件。

View File

@ -643,6 +643,40 @@ public static IEnumerable<T> Page<T>(IEnumerable<T> en, int pageSize, int page)
### FQA
#### Q: 如何將查詢結果轉為 DataTable
提醒 : 不建議使用因為DataTable會將數據`全載入記憶體`失去MiniExcel低記憶體消耗功能。
```C#
public static DataTable QueryAsDataTable(string path)
{
var rows = MiniExcel.Query(path, true);
var dt = new DataTable();
var first = true;
foreach (IDictionary<string, object> row in rows)
{
if (first)
{
foreach (var key in row.Keys)
{
var type = row[key]?.GetType() ?? typeof(string);
dt.Columns.Add(key, type);
}
first = false;
}
dt.Rows.Add(row.Values.ToArray());
}
return dt;
}
```
![image-20210415120352604](https://i.loli.net/2021/04/15/TbtP1GLDEgONueK.png)
### 侷限與警告
- 目前不支援 xls (97-2003) 或是加密檔案。

View File

@ -14,12 +14,27 @@
<RemoveNamespace>System.Transactions</RemoveNamespace>
</Query>
void Main()
{
void Main(){
var doc = XDocument.Parse(xml);
XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("x", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
var dimension = doc.XPathSelectElement("/worksheet/dimension", ns);
}
void Main2()
{
var doc = XDocument.Parse(xml);
XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("x", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
var dimension = doc.XPathSelectElement("/x:worksheet/x:dimension", ns);
Console.WriteLine(dimension); //<dimension ref="A1:B100" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" />