Java操作Excel之Excel文件的下载
2017-04-09 17:00
344 查看
1、有的时候在Web应用会有下载Excel的需求,现分享下后台实现下载Excel文件的代码
2、有关ExcelUtils.java的实现,可以参考上一篇博客的博客Java操作Excel之POI的常用用法
@RequestMapping(value = "/exportExcel", method = {RequestMethod.GET}) public void exportExcel(CorplutionComparisonGroupCustomerDO corplutionComparisonGroupCustomerDO, HttpServletRequest request, HttpServletResponse response){ // 下载的Excel的文件名称 String fileName = "客户名单"; response.setContentType("application/vnd.ms-excel"); String codedFileName = null; OutputStream ops = null; List<CorplutionComparisonGroupCustomerDO> corplutionContactList = new ArrayList<CorplutionComparisonGroupCustomerDO>(); try{ // 进行转码,使其支持中文文件名 codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8"); response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls"); // 产生工作簿对象 //产生工作表对象 corplutionContactList = corplutionComparisonGroupCustomerFacade.findList(corplutionComparisonGroupCustomerDO); Map<String, String> headMap = new LinkedHashMap<String, String>(); headMap.put("CID", "customerId"); headMap.put("客户公司全称", "companyFullName"); Map<String, Object> excelData = ExcelUtils.fillExcelData(headMap, corplutionContactList); List<String> heads = (List<String>) excelData.get("heads"); List<List<String>> dataList = (List<List<String>>)excelData.get("dataList"); HSSFWorkbook workbook = ExcelUtils.createExcelFile(fileName, heads , dataList); ops = response.getOutputStream(); workbook.write(ops); }catch(Exception e){ if (logger.isInfoEnabled()){ logger.error("导出excel异常", e); } } }
2、有关ExcelUtils.java的实现,可以参考上一篇博客的博客Java操作Excel之POI的常用用法
相关文章推荐
- 读取excel文件(jxl.jar包简介/java操作excel jxl.jar下载地址)
- java 多excel下载 打成zip压缩包 程序中创建文件 响应到浏览器(三)
- java 文件的上传和下载的操作
- Java程序员从笨鸟到菜鸟之(一百零四)java操作office和pdf文件(二)利用POI实现数据导出excel报表
- java导出excel java操作文件。文件夹 java制作zip
- mongoDB——java操作mongoDB实现文件上传下载
- Java操作Excel文件导入
- java操作Excel、PDF文件
- java对excel文件的读写操作
- java对excel文件的读写操作,这次是丰富的属性设置
- Java 利用 svnKit 操作SVN 【获取所有文件夹、添加文件、文件下载】
- Java操作文件二(excel)
- Java下载模板文件(Excel demo)
- mongoDB——java操作mongoDB实现文件上传下载
- jxl.jar包简介/java操作excel jxl.jar下载地址
- XSSF POI工程对Excel 2007 OOXML (.xlsx)文件操作的纯Java实现
- Java学习笔记——File类之文件管理和读写操作、下载图片
- Java操作Excel文件导入
- java操作Excel、PDF文件
- JAVA JXL -----excel文件生成、在线打开和下载