Welcome

首页 / 网页编程 / ASP.NET / asp.net Grid 导出Excel实现程序代码

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 名字"
}
]
}
]