【问题标题】:Export Datatable to excel using closedXML exports data with HTML tags and not readable format使用 closedXML 将数据表导出到 excel 导出带有 HTML 标记且格式不可读的数据
【发布时间】: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.


【问题讨论】:

    标签: export-to-excel closedxml


    【解决方案1】:

    ClosedXML 不支持呈现 HTML。它从来没有。我不确定您为什么甚至希望它得到支持。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多