导出HTML表到Excel使用ASP.NET [英] Export HTML Table to Excel using ASP.NET
本文介绍了导出HTML表到Excel使用ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个HTML表(未GridView的),并且没有适当页眉和行。相反,它已定制的结构和数据。我想这个表导出到Excel中。我该怎么办使用ASP.NET?
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?
标签是固定的文本和整数值是从数据库中来。因此,表结构是固定的只有整数/十进制值的变化。
The labels are fixed text and the integer values are coming from database. So the table structure is fixed only the integer/decimal values change.
推荐答案
您想导出HTML表(未GridView的)定制的结构和使用ASP.NET数据到Excel。
You want Export HTML table (Not Gridview) customized structure and data to Excel using ASP.NET.
试试下面的办法
-
提供
ID
并添加=服务器
属性
<表ID =TBLBORDER =1=服务器>
添加以下code
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();
这篇关于导出HTML表到Excel使用ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文