怎么样将table表格中的数据导入到Execl中?
Table的代码如下:
<table width= "98% " border=0 cellpadding=0 cellspacing= "1 " id= "fyftbb " bgcolor= "#000000 ">
<tr bgcolor= "#FFFFFF ">
<td width= "40 "> 编号 </td> <td width= "80 "> 单位 </td>
<%for (int i = 0; i < dt1.Rows.Count; i++)
{
%>
<td width= "80 "> <%=dt1.Rows[i][0].ToString() %> </td>
<%} %>
</tr>
<%for (int r = 0; r < dt3.Rows.Count; r++)
{%>
<tr bgcolor= "#FFFFFF ">
<td> <%=r+1 %> </td>
<td> <%=dt3.Rows[r][0].ToString() %> </td>
<%for (int i = 0; i < dt1.Rows.Count; i++)
{
%>
<td>
<%=bill_value(dt1.Rows[i][0].ToString(),dt3.Rows[r][0].ToString(),dt2) %> </td>
<%} %>
</tr>
<%} %>
<tr bgcolor= "#FFFFFF "> <td> 合计 </td> <td> </td>
<%for (int i = 0; i < dt1.Rows.Count; i++)
{ %>
<td> <%=sum_value(dt1.Rows[i][0].ToString(), dt2)%> </td>
<%} %>
</tr>
</table>
我现在想将上面代码显示出来的数据导入到Execl中去,该怎么做呀?
我用的是asp.net(C#) vs2005
------解决方案--------------------正好手里有一套代码 可以参考下
namespace ThisWeb.Common
{
/// <summary>
/// 实现将一个 System.Web.UI.WebControls.Table 或 DataTable 中的数据,输出到Excel中
/// 作者:海底捞针
/// </summary>
public class Excel
{
private Page m_Pg;
private System.Web.HttpResponse Response;
public Excel(Page pg)
{
this.m_Pg = pg;
Response = this.m_Pg.Response;
Response.Expires = -1;
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel ";
Response.Charset = "gb-2312 ";