程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> asp.net Grid 導出Excel實現程序代碼

asp.net Grid 導出Excel實現程序代碼

編輯:ASP.NET基礎
1. Aspx後台代碼輸出Content Type信息

復制代碼 代碼如下:
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>")


這樣的實現對於簡單的導出數據到Excel已經足夠了。

用法很簡單
引入 bootstrap.js 和壓縮包裡的 export-all.js 就可以使用了
具體可以參考 main.js (下面是定義Grid的時候 指定一個toolbar 為 xtype: 'exporterbutton')

復制代碼 代碼如下:
height: 350,
width: 600,
title: 'Array Grid',
renderTo: 'grid-example',
viewConfig: {
stripeRows: true
},
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'exporterbutton',
store: myStore

//一下兩項配置 已在Buttion.js中 配置了默認路徑 不需要重復指定
//swfPath: './downloadify.swf',
//downloadImage: './download.png',

//這裡可以根據當表格 給 定制導出的文件名
//downloadName:'導出的Excel 名字'
}
]
}
]
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved