asp.net Grid 導出Excel實現(xiàn)程序代碼
更新時間:2012年12月29日 10:07:55 作者:
看了FineUI中的將Grid導出為Excel的實現(xiàn)方法,實際上是可以非常簡單??磥砗茈y的問題,變換一種思路就可以非常簡單
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>")
這樣的實現(xiàn)對于簡單的導出數(shù)據(jù)到Excel已經(jīng)足夠了。
用法很簡單
引入 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',
//這里可以根據(jù)當表格 給 定制導出的文件名
//downloadName:'導出的Excel 名字'
}
]
}
]
復制代碼 代碼如下:
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>")
這樣的實現(xiàn)對于簡單的導出數(shù)據(jù)到Excel已經(jīng)足夠了。
用法很簡單
引入 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',
//這里可以根據(jù)當表格 給 定制導出的文件名
//downloadName:'導出的Excel 名字'
}
]
}
]
您可能感興趣的文章:
- ASP.NET使用GridView導出Excel實現(xiàn)方法
- asp.net導出excel數(shù)據(jù)的常見方法匯總
- asp.net導出excel的簡單方法實例
- ASP.NET導出數(shù)據(jù)到Excel的實現(xiàn)方法
- Asp.net中DataTable導出到Excel的方法介紹
- ASP.NET用DataSet導出到Excel的方法
- .Net中導出數(shù)據(jù)到Excel(asp.net和winform程序中)
- asp.net生成Excel并導出下載五種實現(xiàn)方法
- asp.net GridView導出到Excel代碼
- ASP.NET 導出到Excel時保留換行的代碼
- asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel的方法
相關(guān)文章
.Net?Core應用增強型跨平臺串口類庫CustomSerialPort()詳解
本文詳細講解了.Net?Core應用增強型跨平臺串口類庫CustomSerialPort(),文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-01-01.NET調(diào)用控制臺下生成的exe文件,傳參及獲取返回參數(shù)的思路及代碼
.NET調(diào)用控制臺下生成的exe文件,傳參及獲取返回參數(shù)的思路及代碼,需要的朋友可以參考一下2013-06-06asp.net下String.prototype.split()的兼容問題
IE下的String.prototype.split()函數(shù)bug2012-12-12ASP.NET中MVC從后臺控制器傳遞數(shù)據(jù)到前臺視圖的方式
這篇文章主要介紹了ASP.NET中MVC從后臺控制器傳遞數(shù)據(jù)到前臺視圖的方式,以實例形式較為詳細的分析了asp.net中MVC數(shù)據(jù)傳遞的具體實現(xiàn)方法,需要的朋友可以參考下2014-12-12asp.net中如何批量導出access某表內(nèi)容到word文檔
最近有項目需求是這樣的,需要將某表中的每一條記錄中的某些內(nèi)容導出在一個word文檔中。下面小編就把我的解決辦法分享給大家,供大家參考2015-10-10"PageMethods未定義"或"對象不支持此屬性或方法"解決方法分享
PageMethods未定義或?qū)ο蟛恢С执藢傩曰蚍椒ń鉀Q方法,需要的朋友可以參考下。2010-12-12