日期:2014-05-17  浏览次数:20381 次

ASP.Net 海量数据导出到EXCEL (求救,问题很老,但是很急)
论坛的帖子
http://topic.csdn.net/u/20080827/11/e8eb5429-1f76-4ad5-9fe0-db217bf991e6.html
讨论海量数据导出到EXCEL ,不太适用于asp.net 
还有人总结Asp.net 数据导出到EXCEL 
http://www.cnblogs.com/lishengpeng1982/archive/2008/04/03/1135490.html
数据量大了(一万条以上),恐怕也不行,
我们目前采用的是下面的方法 ,6000条数据可以导出,速度也可以,数据再多就不行了,希望大家指点,谢谢了。

public void CreateExcel(System.Web.UI.Page page,string strHtml)
{
HttpResponse resp;
string strOutputHtml="";
strOutputHtml=strHtml;
string strFileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; //xlsx xls
resp = page.Response;
resp.Clear();
resp.Buffer = false;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + strFileName); //inline,attachment
resp.ContentType = "application/ms-excel"; //vnd.ms-excel vnd.xls
//向HTTP输出流中写入 
resp.Write(strOutputHtml);
resp.Flush();
resp.End();

}
其中方法的第二个参数 strHtml 是 html格式的数据的字符串,如下:
<html xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'
  xmlns:w='urn:schemas-microsoft-com:office:word' xmlns:x='urn:schemas-microsoft-com:office:excel'
  xmlns='http://www.w3.org/TR/REC-html40'>
<head>
  <meta http-equiv='Content-Type' content='application/ms-excel; charset=gb2312'>
  <meta name='ProgId' content='Excel.Sheet'>
  <meta name='Generator' content='Microsoft Excel 12'>
</head>
<body lang='ZH-CN' style='tab-interval: 21.0pt; text-justify-trim: punctuation'>
  <table border='1'>
  <tr height='36'>
  <td align='center' colspan='27' style='font-size: 18px; font-family: 宋体;'>
  查询列表</td>
  </tr>
  <tr height='25'>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  WN_ID</td>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  WT_ID</td>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  WN_Name</td>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  WN_Code</td>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  WN_IsMailStone</td>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  WN_Status</td>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  Creater</td>
  <td width='120' align='LEFT' style='font-family: 宋体; font-size: 12px;' nowrap>
  CreateTime</td>
   
   
  </tr>
   
  <tr height='25'>
  <td align='LEFT' style="font-family: 宋体; font-size: 12px; height: 25px;" x:str="\"'WN070130000007\">
  WN070130000007</td>
  <td align='LEFT' style="font-family: 宋体; font-size: 12px; height: 25px;" x:str="\"'WT0000000000000001\">
  WT0000000000000001</td>