【问题标题】:export HTML Table to excel with grouping in ASP.net使用 ASP.net 中的分组将 HTML 表导出到 Excel
【发布时间】:2016-09-03 15:16:29
【问题描述】:

我在将 HTML 表导出到 ASP.net 中的分组时遇到问题。

这是我的代码导出到excel而不分组

请帮帮我。

Dim sFileName As String = Session("UserName") + " " +cboCustomer.Text.Replace(",", "-") + ".xls"
Dim StrHtmlGenerate As New StringBuilder() Dim StrExport As New StringBuilder() 
Response.ContentType = "application/x-msexcel" 
Response.AddHeader("Content-Disposition", "attachment; filename=" + sFileName) 
Response.ContentEncoding = Encoding.UTF8 Dim tw As New StringWriter() 
Dim hw As New HtmlTextWriter(tw) litTable.RenderControl(hw) Response.Write(tw.ToString()) 
Response.End()

【问题讨论】:

  • Dim sFileName As String = Session("UserName") + " " + cboCustomer.Text.Replace(",", "-") + ".xls" Dim StrHtmlGenerate As New StringBuilder() Dim StrExport As New StringBuilder() Response.ContentType = "application/x-msexcel" Response.AddHeader("Content-Disposition", "attachment; filename=" + sFileName) Response.ContentEncoding = Encoding.UTF8 Dim tw As New StringWriter() Dim hw As New HtmlTextWriter(tw) litTable.RenderControl(hw) Response.Write(tw.ToString()) Response.End()

标签: c# html asp.net vb.net export-to-excel


【解决方案1】:

尝试使用下面的代码。虽然它在 C# 中,但可能对您有所帮助。

        Response.AppendHeader("content-disposition", "attachment;filename=ExportToExcel.xls");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.ms-excel";
        this.EnableViewState = false;
        Response.Write(HTMLDiv.InnerHtml);
        Response.End();

其中 HTMLDiv 是包含 HTML 的 HTML“div”元素

【讨论】:

  • 我使用 创建 html 表
  • 我使用 和 htmlTable.AppendLine("" 之类的 vb 代码创建 html 表) ... htmlTable.AppendLine("
    ")。在您的示例代码中的哪个部分在 excel 中创建分组?
  • @Ishaq,请参阅此站点以获取进一步的操作c-sharpcorner.com/UploadFile/ankurmalik123/…
猜你喜欢
  • 2012-03-10
  • 1970-01-01
  • 1970-01-01
  • 2013-03-11
  • 2019-10-21
  • 1970-01-01
  • 1970-01-01
  • 2021-04-06
  • 1970-01-01
相关资源
最近更新 更多