当前位置:Gxlcms > asp.net > asp.net Grid 导出Excel实现程序代码

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

时间:2021-07-01 10:21:17 帮助过:47人阅读

1. Aspx后台代码输出Content Type信息

代码如下:
  1. <br>Response.ClearContent(); <br>Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls"); <br>Response.ContentType = "application/excel"; <br>Response.Write(GetGridTableHtml(Grid1)); <br>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')

代码如下:
  1. <br>height: 350, <br>width: 600, <br>title: 'Array Grid', <br>renderTo: 'grid-example', <br>viewConfig: { <br>stripeRows: true <br>}, <br>dockedItems: [ <br>{ <br>xtype: 'toolbar', <br>dock: 'top', <br>items: [ <br>{ <br>xtype: 'exporterbutton', <br>store: myStore <br><br>//一下两项配置 已在Buttion.js中 配置了默认路径 不需要重复指定 <br>//swfPath: './downloadify.swf', <br>//downloadImage: './download.png', <br><br>//这里可以根据当表格 给 定制导出的文件名 <br>//downloadName:'导出的Excel 名字' <br>} <br>] <br>} <br>] <br>

人气教程排行