使用closedXML将数据表导出到excel导出带有HTML标记且格式不可读的数据



我正在尝试将数据表导出到excel。我使用的是closedXML。我的数据表包含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.

ClosedXML不支持呈现HTML。它从来没有。我不确定你为什么期望得到支持。

最新更新