【发布时间】:2021-11-17 13:01:35
【问题描述】:
我正在尝试将数据表导出到 Excel。我正在使用封闭的XML。我的数据表包含 HTML 标签。导出 excel 是使用 HTML 标记而不是可读格式导出数据。 我的代码如下
public static MemoryStream ConvertDataTableToExcel(DataTable dt, string name, bool addColumnNames = true)
{
var stream = new MemoryStream();
if (dt != null)
{
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add(name);
var rowno = 1;
var colno = 1;
if (addColumnNames)
{
//get column list and add as first row
foreach (DataColumn column in dt.Columns)
{
worksheet.Cell(rowno, colno).Value = StripHTML(column.ColumnName);
colno++;
}
}
foreach (DataRow dr in dt.Rows)
{
++rowno;
colno = 1;
foreach (DataColumn column in dt.Columns)
{
worksheet.Cell(rowno, colno).Value=(dr[column.ColumnName].ToString());
++colno;
}
}workbook.SaveAs(stream);
}
}
return stream;
}
我当前在 excel 单元格中的输出是:
<ol start="6"><li>In observing the inventory, you should check:<ol type="a"><li>From reported counts to stock</li><li>From stock to reported counts</li><li>Identity of inventory items.</li></ol></li><ol>```
My expected output is :
6.In observing the inventory, you should check:
a.From reported counts to stock
b.From stock to reported counts
c.Identity of inventory items.
【问题讨论】: