组件下载:
http://www.liuchang.org/extjs-grid-qian-tai-dao-chu-excel-zu-jian/
1、下载文件解压后有个文件夹 extexcel ,把它复制到你的项目中。
2、在页面中引入js
<script src="extexcel/export-all.js" type="text/javascript"></script>;
3、在grid中即可使用 导出按钮了:
xtype:'gridpanel',
tbar: ['-',
{
xtype:'button',
text:'新建',
action:'newBtn'
},'-',{
xtype: 'button',
text: '编辑',
action:'editBtn'
},'-',{
xtype:'button',
text:'删除',
action:'deleteBtn'
},'-',{
xtype:'button',
text:'刷新',
action:'refreshBtn'
},'-',{
//导出按钮,并指定grid的store
xtype: 'exporterbutton',
store: store
}
],
selModel : Ext.create('Ext.selection.CheckboxModel',{
// mode : 'SINGLE'
}),
store:store,
columns: [
{ text: '名称', dataIndex: 'p_name' ,width:300},
{ text: '分类', dataIndex: 'p_categoryname' },
{ text: '时间', dataIndex: 'p_addtime',width:200 }
],
需要注意的事项:
1、导出文件只能用2003打开。
2、如果grid中有checkbox将会导致导出的excel文件中内容和表头错位
3、导出的excel文件不能用poi读取,我是在网上看到的代码,我查了些资料,因为头文件信息的问题,所以如果用poi读取会报错,如果有高人可以修改下,当然,如果只是导出,不需要poi导入的话这个足以满足了