Ext 导出Excel的一种模式

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

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

同时和ext推荐的 one page,one appllication理念不冲突

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

 

 

//后台的例子

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

 

你可能感兴趣的:(Web,ext,Excel)