简体   繁体   English

导出 HTML 表格以在 ASP.net 中分组

[英]export HTML Table to excel with grouping in ASP.net

I have a problem to export HTML Table to excel with grouping in ASP.net.我在使用 ASP.net 中的分组将 HTML 表导出为 excel 时遇到问题。

this my code export to excel without grouping这是我的代码导出到 excel 而不分组

Please help Me.请帮我。

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()

Try to use below code.尝试使用下面的代码。 Though its in C#, might be helpful for you.虽然它在 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();

Where HTMLDiv is the HTML "div" element that contains the HTML其中 HTMLDiv 是包含 HTML 的 HTML“div”元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM