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();  

posted @ 2011-05-13 10:15  Joly-Han  阅读(741)  评论(0编辑  收藏  举报