I have an html table (Not Gridview) and that has no proper Header and rows. Instead it has customized structure and data. I want to export this table to Excel. How can I do using ASP.NET?
标签是固定文本,整数值来自数据库。因此表结构是固定的,只有整数/小数值发生变化。
您希望使用 ASP.NET 将 HTML 表(不是 Gridview)自定义结构和数据导出到 Excel。
尝试以下方法
-
提供ID
并添加runat="server"
属性
<table id="tbl" runat="server" >
-
添加以下代码
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment;
filename=ExcelFile.xls");
Response.ContentEncoding = Encoding.UTF8;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
tbl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)