标签:int encode excel mat gets for print i++ taf
public HSSFWorkbook generateSheet(HSSFWorkbook wb, String sheetName, List<StaffDeclareInfoDO> list) { /*** 总记录数 **/ int listSize = list == null ? 0 : list.size(); HSSFSheet sheet = wb.createSheet(sheetName); HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell((short) 0); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue("序号"); cell = row.createCell((short) 1); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue("姓名"); cell = row.createCell((short) 2); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue("性别"); cell = row.createCell((short) 3); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue("手机"); cell = row.createCell((short) 4); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue("身份证号"); cell = row.createCell((short) 5); for (int i = 0; i < listSize; i++) { row = sheet.createRow(i + 1); StaffDeclareInfoDO data = list.get(i); cell = row.createCell((short) 0); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(data.getId()); cell = row.createCell((short) 1); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(data.getName()); cell = row.createCell((short) 2); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(data.getSex()); cell = row.createCell((short) 3); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(data.getMobile()); cell = row.createCell((short) 4); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(data.getCertificate()); } return wb; }
public void export(HSSFWorkbook wb, HttpServletResponse response) { try { String tip = DateUtil.format(new Date(), DateUtil.shortFormat) + ""; String name = "xxx" + tip; response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(name, "utf-8") + ".xls"); OutputStream out = response.getOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); wb.write(baos); byte[] xlsBytes = baos.toByteArray(); out.write(xlsBytes); out.close(); } catch (Exception e) { e.printStackTrace(); } }
标签:int encode excel mat gets for print i++ taf
原文地址:https://www.cnblogs.com/qcxdoit/p/9927560.html