extjs grid 导出到excel

1.先准备好二个引用文件  exportexcel.jsp  &  grdToExcel.js

2.在index.jsp 中引入 grdToExcel.js

3. 在导出的js中加入如下代码

 //导出按钮定义
    var exportExcelButton = new Ext.Button({
        text: '导出到Excel',
        iconCls : 'btn-xls',
        handler: function() {
            var grid = Ext.getCmp("CalendarPlanGrid1");
            
            var vExportContent = grid.getExcelXml();
            if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8 || Ext.isIE9 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3) {
                var fd=Ext.get('frmDummy');
                if (!fd) {
                    fd=Ext.DomHelper.append(Ext.getBody(),{tag:'form',method:'post',id:'frmDummy',action:'js/exportexcel.jsp', target:'_blank',name:'frmDummy',cls:'x-hidden',cn:[
                        {tag:'input',name:'exportContent',id:'exportContent',type:'hidden'}
                    ]},true);
                }
                fd.child('#exportContent').set({value:vExportContent});
                fd.dom.submit();
            } else {
                document.location = 'data:applicationnd.ms-excel;base64,'+Base64.encode(vExportContent);
            }}
    });

 

 

var grid = Ext.getCmp("CalendarPlanGrid1");

 

 

如有任何疑问:email to   [email protected]

你可能感兴趣的:(Excel,ExtJs,grid,导出)