欢迎来到天天文库
浏览记录
ID:38183797
大小:97.50 KB
页数:3页
时间:2019-05-24
《ExtJS实现Excel导出》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、ExtJS实现Excel导出ExtJS是一种基于客户端开发的AJAX应用,是一个与后台技术无关的前台ajax框架。由于项目需求,我们需要实现Excel的导出功能,前台界面是用ExtJS实现。如何实现呢?1.使用POI组件实现excel导出功能//获取问题列表ListtargetStockList=suggestionService.getSuggestionList(map);//创建一个新的ExcelHSSFWorkbookworkBook=newHSSFWorkbook();//创建sheet页HSSFSheetsheet=workBook.cr
2、eateSheet();//sheet页名称workBook.setSheetName(0,"targetStockList");//创建header页HSSFHeaderheader=sheet.getHeader();//设置标题居中header.setCenter("标题");//设置第一行为HeaderHSSFRowrow=sheet.createRow(0);HSSFCellcell0=row.createCell(Short.valueOf("0"));HSSFCellcell1=row.createCell(Short.valueOf("1"));HSSFCe
3、llcell2=row.createCell(Short.valueOf("2"));//设置字符集cell0.setEncoding(HSSFCell.ENCODING_UTF_16);cell1.setEncoding(HSSFCell.ENCODING_UTF_16);cell2.setEncoding(HSSFCell.ENCODING_UTF_16);cell0.setCellValue("问题标题");cell1.setCellValue("问题描述");cell2.setCellValue("反馈时间");if(targetStockList!=null&&!
4、targetStockList.isEmpty()){for(inti=0;i5、Cell.ENCODING_UTF_16);cell1.setEncoding(HSSFCell.ENCODING_UTF_16);cell2.setEncoding(HSSFCell.ENCODING_UTF_16);cell0.setCellValue(targetStock.getType());cell1.setCellValue(targetStock.getContent());cell2.setCellValue(targetStock.getPublishTime());sheet.setColumnWidth((short)0,(short)4000);s6、heet.setColumnWidth((short)1,(short)4000);sheet.setColumnWidth((short)2,(short)4000);}}//通过Response把数据以Excel格式保存response.reset();response.setContentType("application/msexcel;charset=UTF-8");try{response.addHeader("Content-Disposition","attachment;filename=""+newString(("用户意见信息表"+".xls").g7、etBytes("GBK"),"ISO8859_1")+""");OutputStreamout=response.getOutputStream();workBook.write(out);out.flush();out.close();}catch(Exceptione){e.printStackTrace();}returnnull;2.ExtJS调用此函数,实现Excel的导出我们知道在界面上通过一个按钮实现Excel的导出,ExtJS的按钮一般都是通过Ext.Ajax.request的异步请求实现数据提
5、Cell.ENCODING_UTF_16);cell1.setEncoding(HSSFCell.ENCODING_UTF_16);cell2.setEncoding(HSSFCell.ENCODING_UTF_16);cell0.setCellValue(targetStock.getType());cell1.setCellValue(targetStock.getContent());cell2.setCellValue(targetStock.getPublishTime());sheet.setColumnWidth((short)0,(short)4000);s
6、heet.setColumnWidth((short)1,(short)4000);sheet.setColumnWidth((short)2,(short)4000);}}//通过Response把数据以Excel格式保存response.reset();response.setContentType("application/msexcel;charset=UTF-8");try{response.addHeader("Content-Disposition","attachment;filename=""+newString(("用户意见信息表"+".xls").g
7、etBytes("GBK"),"ISO8859_1")+""");OutputStreamout=response.getOutputStream();workBook.write(out);out.flush();out.close();}catch(Exceptione){e.printStackTrace();}returnnull;2.ExtJS调用此函数,实现Excel的导出我们知道在界面上通过一个按钮实现Excel的导出,ExtJS的按钮一般都是通过Ext.Ajax.request的异步请求实现数据提
此文档下载收益归作者所有