ext导出excel
Ext导出excel很麻烦的,我们可以打开一个window.open()或window.location.href=''发送请求;把操作excel的工作交给后台的action处理就行了JS代码:var grid =new Ext.grid.GridPanel({region:'center',store:store,cm:cm, tbar : [{text : "导出",iconCls:"post",handler :exportToExcel}]});var resultView = new Ext.Viewport( {layout : 'border',items : });}//导出excel表function exportToExcel(){var appWindow = window.open("xxx.action", "menubar=0,scrollbar=0,resizable=1,channelmode=1,location=0,status=1");appWindow.focus();//也可以用location.href来发送请求//window.location.href="xxx.action?ids=123456";}action代码:public boolean exportToExcel(HttpServletResponse response, List list)throws Exception {OutputStream os = response.getOutputStream();WritableWorkbook wbook = Workbook.createWorkbook(os);WritableSheet wsheet = wbook.createSheet("合同信息", 0);Label label =newLabel(0,0 ,"test"); Label label1 =newLabel(0,1 ,"test1"); wsheet.addCell(label);wsheet.addCell(label1); response.setHeader("Content-disposition","attachment; filename=contract.xls");response.setContentType("application/vnd.ms-excel");wbook.write(); // 写入文件wbook.close();os.close(); // close outputStreamreturn true;}
页:
[1]