C# 带有HTML输入的EPPlus

C# 带有HTML输入的EPPlus,c#,asp.net,sharepoint,export-to-excel,C#,Asp.net,Sharepoint,Export To Excel,我有一个数据表正在转换为excel。为此,我使用EPPlus dll。这里我得到生成的excel文件。但我的问题是有两列存在富文本值。转换后,上面的列始终显示带有HTML标记的数据。我如何解决这个问题。请帮帮我。提前谢谢 我的代码如下所示 try { using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb web = site.OpenWeb()) {

我有一个数据表正在转换为excel。为此,我使用EPPlus dll。这里我得到生成的excel文件。但我的问题是有两列存在富文本值。转换后,上面的列始终显示带有HTML标记的数据。我如何解决这个问题。请帮帮我。提前谢谢

我的代码如下所示

 try
 {
    using (SPSite site = new SPSite(SPContext.Current.Web.Url))
    {
        using (SPWeb web = site.OpenWeb())
        {
             DataTable dtTemp = new DataTable();
             if (ViewState["DTSource"] != null)
                 dtTemp = (DataTable)ViewState["DTSource"];

             using (ExcelPackage pck = new ExcelPackage())
             {
                 //Create the worksheet
                 ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Sheet1");
                 //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                 if (dtTemp != null && dtTemp.Rows.Count > 0)
                 {
                     ws.Cells["A1"].LoadFromDataTable(dtTemp, true);
                     using (ExcelRange rng = ws.Cells["A1:" + GetColumnName(dtTemp.Columns.Count) + "1"])
                     {
                         rng.Style.Font.Bold = true;
                         rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
                         rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));
                         rng.Style.Font.Color.SetColor(Color.White);
                     }

                     for (int i = 0; i < dtTemp.Columns.Count; i++)
                     {
                         if (dtTemp.Columns[i].DataType.FullName.Contains("DateTime"))
                         {
                             ws.Cells[2, i + 1, dtTemp.Rows.Count + 1, i + 1].Style.Numberformat.Format = "MM/dd/yyyy";
                             ws.Column(i + 1).Width = 15;
                         }

                         using (ExcelRange col = ws.Cells[2, 1, 2 + dtTemp.Rows.Count, 1])
                         {
                            col.Style.Numberformat.Format = "#,##0.00";
                            col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                         }
                         using (ExcelRange col = ws.Cells[2, 4, 2 + dtTemp.Rows.Count, 4])
                         {
                             col.IsRichText = true;
                             col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
                         }
                         Page.Response.Clear();
                         Page.Response.AddHeader("content-disposition", "attachment; filename=ExceptionTracker_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
                         Page.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                         Page.Response.BinaryWrite(pck.GetAsByteArray());
                         Page.Response.End();
                     }
                 }
                 else
                 {
                     string script = "window.frameElement.cancelPopUp(); return false;";
                     Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close Window", script, true);
                 }
             }
         }
     }
 }
 catch (Exception ex)
 {
      throw ex;
 }

这部分不应该在别的地方吗?也许在您完成创建文件之后

Page.Response.Clear();
Page.Response.AddHeader("content-disposition", "attachment; filename=ExceptionTracker_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
Page.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Page.Response.BinaryWrite(pck.GetAsByteArray());
Page.Response.End();

请将您的代码棒显示在您认为错误所在的位置。@Serv:我已经用我的代码更新了