导出数据 org.apache.poi.hssf.usermodel.HSSFWorkbook
2017-03-09 10:45
531 查看
Map<String,Object> params = (Map<String, Object>) request.getSession().getAttribute(DOWNLOADPARAMSKEY); if(null == params){ response.getWriter().print("error request"); return; } String fileName = String.format("%s.xls", new Date().getTime()); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); List<ExportSigningInfo> applyInfoList = signingOnlineNewService.getExportSigningInfoList(params); log.info("data size:"+ applyInfoList.size()); HSSFWorkbook book = new HSSFWorkbook(); HSSFSheet sheet = book.createSheet("在线签约申请记录"); sheet.setColumnWidth(0, 30 * 256); sheet.setColumnWidth(1, 13 * 256); sheet.setColumnWidth(2, 10 * 256); sheet.setColumnWidth(3, 35 * 256); sheet.setColumnWidth(4, 10 * 256); sheet.setColumnWidth(5, 10 * 256); sheet.setColumnWidth(6, 20 * 256); sheet.setColumnWidth(7, 10 * 256); sheet.setColumnWidth(8, 20 * 256); sheet.setColumnWidth(9, 10 * 256); sheet.setColumnWidth(10, 10 * 256); sheet.setColumnWidth(11, 12 * 256); sheet.setColumnWidth(12, 10 * 256); sheet.setColumnWidth(13, 10 * 256); HSSFRow titleRow = sheet.createRow((short)0); CellStyle titleStyle = getTitleStyle(book); for (int i = 0; i < TITLES.length; i++) { HSSFCell cell = titleRow.createCell(i); cell.setCellStyle(titleStyle); cell.setCellValue(TITLES[i]); } // CellStyle gridStyle = getRowStyle(book); for (int i = 0; i < applyInfoList.size(); i++) { HSSFRow gridRow = sheet.createRow(1+i); // gridRow.setRowStyle(gridStyle); // 合同流水号、 gridRow.createCell(0).setCellValue(applyInfoList.get(i).getSerialNum()); // 申请人手机号、 gridRow.createCell(1).setCellValue(applyInfoList.get(i).getApplyMobile()); // 个人/公司名称、 gridRow.createCell(2).setCellValue(applyInfoList.get(i).getCustomerName()); // 个人/公司地址、 gridRow.createCell(3).setCellValue(applyInfoList.get(i).getCustomerAddr()); // 联系人、 gridRow.createCell(4).setCellValue(applyInfoList.get(i).getApplyUserName()); // 申请状态、 gridRow.createCell(5).setCellValue(applyInfoList.get(i).getStatus()); // 申请时间、 gridRow.createCell(6).setCellValue(applyInfoList.get(i).getApplyTm()); // 生效日期、 gridRow.createCell(7).setCellValue(applyInfoList.get(i).getTakeEffectTM()); // 月结账号、 gridRow.createCell(8).setCellValue(applyInfoList.get(i).getCardNo()); // 开发人员工号、 gridRow.createCell(9).setCellValue(applyInfoList.get(i).getDevEmpNum()); // 网络代码、 gridRow.createCell(10).setCellValue(applyInfoList.get(i).getNetCode()); // 快递决策人手机、 gridRow.createCell(11).setCellValue(applyInfoList.get(i).getDecMakerMobile()); // 快递决策人电话、 gridRow.createCell(12).setCellValue(applyInfoList.get(i).getDecMakerTelePhone()); // 主要寄件人手机 gridRow.createCell(13).setCellValue(applyInfoList.get(i).getMostConsignorMobile()); } book.write(response.getOutputStream()); //清理session中的参数 //这里暂时不清理,因为360浏览器请求了两次当前网关,导致下载失败!(第一次请求时正常,第二次请求时session中的参数已经被清空了,故会报错!) // request.getSession().removeAttribute(DOWNLOADPARAMSKEY);
/** * 列标题样式 * * @param wb * @return */ private CellStyle getTitleStyle(HSSFWorkbook wb) { CellStyle style = wb.createCellStyle(); style.setFont(getFont(wb)); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setBorderBottom((short) 1); style.setBorderLeft((short) 1); style.setBorderRight((short) 1); style.setBorderTop((short) 1); style.setBottomBorderColor(HSSFColor.BLACK.index); return style; }
/** * 字体样式 * * @param wb * @return */ private HSSFFont getFont(HSSFWorkbook wb) { HSSFFont font = wb.createFont(); font.setFontName("Arial"); font.setFontHeightInPoints((short) 10); return font; }
相关文章推荐
- org.apache.poi.hssf.usermodel.HSSFWorkbook 进行处理导出Excel操作
- 导入数据 org.apache.poi.hssf.usermodel.HSSFWorkbook
- org.apache.poi.hssf.usermodel.HSSFWorkbook和org.apache.poi.xssf.usermodel.XSSFWorkbook的区别
- Java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook异常的解决方法
- org.apache.poi.ss.usermodel 类操作excel数据遗漏
- java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook 错误来源
- org.apache.poi.ss.usermodel 类操作excel数据遗漏
- 异常:java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.getCellStyleAt
- java操作Excel(org.apache.poi.hssf.usermodel)
- java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.getMergedRegion
- org.apache.poi.ss.usermodel 类操作excel数据遗漏
- POI poi/wp/usermo Caused by: java.lang.ClassNotFoundException: org.apache.poi.wp.usermodel.Paragraph
- java 利用org.apache.poi.hssf包编写excel导出文件
- JAVA POI HSSFWorkbook 导出Excel表格超大数据量解决方案
- org.apache.poi.ss.usermodel.Cell判断是否为空的方法
- poi docx转html遇到空指针问题或java.lang.NoClassDefFoundError: org/apache/poi/xwpf/usermodel/IRunBody
- Excel Handle by org.apache.poi.xssf.usermodel.*
- apache-poi 实现大数据导出到excel中
- 用org.apache.poi将Excel里的数据导入数据库
- Apache中的poi包中的XSSFWorkbook与HSSFWorkbook的区别