欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Grid或者DataTable中數(shù)據(jù)導(dǎo)出為Excel原來這么簡(jiǎn)單

 更新時(shí)間:2012年12月24日 18:08:13   作者:  
以前一直認(rèn)為,將Grid 或者DataTable中的數(shù)據(jù)導(dǎo)出到Excel功能實(shí)現(xiàn)會(huì)非常復(fù)雜,可能會(huì)想用什么類庫(kù)什么的或者實(shí)在太難就用csv算了,沒想到真的很簡(jiǎn)單,需要了解的朋友可以參考下
以前一直認(rèn)為,將Grid 或者DataTable中的數(shù)據(jù)導(dǎo)出到Excel功能實(shí)現(xiàn)會(huì)非常復(fù)雜,可能會(huì)想用什么類庫(kù)什么的或者實(shí)在太難就用csv算了。

看了FineUI中的將Grid導(dǎo)出為Excel的實(shí)現(xiàn)方法,實(shí)際上是可以非常簡(jiǎn)單??磥砗茈y的問題,變換一種思路就可以非常簡(jiǎn)單。
1. Aspx后臺(tái)代碼輸出Content Type信息
復(fù)制代碼 代碼如下:

Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
Response.Write(GetGridTableHtml(Grid1));
Response.End();2. 直接輸出Html代碼
Response.Write(@"
<table border="1">
<tr>
<td>Excel</td>
<td>By Html</td>
</tr>
</table>")

這樣的實(shí)現(xiàn)對(duì)于簡(jiǎn)單的導(dǎo)出數(shù)據(jù)到Excel已經(jīng)足夠了。
檢驗(yàn)方法:直接把html代碼保存為Excel文件,就可以看到效果。

相關(guān)文章

最新評(píng)論