读书人

如何样将table表格中的数据导入到Exec

发布时间: 2012-01-20 18:53:53 作者: rapoo

怎么样将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 ";
Response.AppendHeader( "content-disposition ", "inline ");


Response.Write( " <html xmlns:o= 'urn:schemas-microsoft-com:office:office ' xmlns:x= 'urn:schemas-microsoft-com:office:excel ' xmlns= 'http://www.w3.org/TR/REC-html40 '> <head> <meta name= 'ProgId ' content= 'Excel.Sheet '> <meta name= 'Generator ' content= 'Microsoft Excel 11 '> \n " +
" <!--[if gte mso 9]> <xml> \n " +
" <o:DocumentProperties> \n " +
" <o:Author> MC SYSTEM </o:Author> \n " +
" <o:LastAuthor> MC SYSTEM </o:LastAuthor> \n " +
" <o:Created> 2005-03-22T05:13:09Z </o:Created> \n " +
" <o:LastSaved> 2005-03-23T03:15:19Z </o:LastSaved> \n " +
" <o:Company> jtgd </o:Company> \n " +
" <o:Version> 11.5606 </o:Version> \n " +
" </o:DocumentProperties> \n " +
" </xml> <![endif]--> \n " +
" <!--[if gte mso 9]> <xml> \n " +
" <x:ExcelWorkbook> \n " +
" <x:ExcelWorksheets> \n " +
" <x:ExcelWorksheet> \n " +
" <x:Name> Sheet1 </x:Name> \n " +
" <x:WorksheetOptions> \n " +
" <x:ProtectScenarios> False </x:ProtectScenarios> \n " +
" </x:WorksheetOptions> \n " +
" </x:ExcelWorksheet> \n " +
" </x:ExcelWorksheets> \n " +
" <x:WindowHeight> 9675 </x:WindowHeight> \n " +
" <x:WindowWidth> 11700 </x:WindowWidth> \n " +
" <x:WindowTopX> 240 </x:WindowTopX> \n " +
" <x:WindowTopY> 105 </x:WindowTopY> \n " +
" </x:ExcelWorkbook> \n " +
" </xml> <![endif]--> \n " +
" <style> \n " +
" .brow{border-left:1px solid white;border-top:1px solid white;border-right:1px solid white;} " +
" </style> \n " +
" </head> \n " +
" <body> \n " +
" <table ID= 'Table1 ' border= '1 ' cellPadding= '1 ' cellspacing= '1 '> ");

}

读书人网 >asp.net

热点推荐