Ext 导出Excel的一种模式

为按钮或者菜单关联如下的函数,内容根据具体需求而定

通过调用window.open('url'),将请求和参数传导后台,然后再后台通过文件流写出,可以比较优雅的导出excel文

EXTJS代码:

function exportExcel(){   

       var startDate = Ext.util.Format.date(historyAchievementStore.baseParams['startDate'],'Y-m-d');    

       var endDate = Ext.util.Format.date(historyAchievementStore.baseParams['endDate'],'Y-m-d');   

         var searchType = historyAchievementStore.baseParams['searchType'];   

        var department_id = historyAchievementStore.baseParams['department_id'];   

        var department_name = historyAchievementStore.baseParams['department_name'];   

        if(startDate == null || department_name == null){   

            Ext.Msg.alert('系统信息','请先查找数据');   

            return false;   

        }   

        var appWindow = window.open("export/export_exportDepAchievement.action?startDate=" + startDate + "&endDate=" + endDate + "&searchType=" + searchType +"&department_id=" + department_id + "&department_name=" + encodeURI(department_name) + "&page=1"); //调action得到数据生成execl格式的数据,response发往前台    

                         

           appWindow.focus();   

          

    } 

JAVA代码:

response.setHeader("Content-disposition","attachment;" +   

                    "filename="new String((department_name + "业绩").getBytes("GBK"), "ISO_8859_1") + ".xls");     

          response.setContentType("application/vnd.ms-excel");     

            WritableWorkbook wbook = ExcelUtil.createDepAchievement(staff.getStaff_name(), getSearchTypeDesc(),department_name,department_id, searchType, startDate, endDate, page,response.getOutputStream());   

            wbook.write();   

            wbook.close();   

            response.getOutputStream().close();  

转载于:https://www.cnblogs.com/joly-han/archive/2011/05/13/2045200.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值