网络编程 
首页 > 网络编程 > 浏览文章

asp.net Grid 导出Excel实现程序代码

(编辑:jimmy 日期: 2026/1/1 浏览:3 次 )
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 名字'
}
]
}
]
上一篇:使用C#处理WebBrowser控件在不同域名中的跨域问题
下一篇:GridView分页代码简单万能实用
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap