-
poi导致中文excel
List<Map<String, Object>> exportList = dsjService.getExportList(dsjDetail); String[][] map = { {"序号","ID"}, {"需求类型","XQ_TYPE"}, {"标题","TITLE"}, {"正文","GD_INFO"}, {"工单发起时间","CREATE_DATE_SHOW"}, {"发起人","OPER_NAME"}, {"发起人号码","OPER_MOBILE"}, {"区县","ORG_1_NAME"}, {"分局","ORG_2_NAME"}, {"当前环节","CURRENT_TASK"}, {"当前处理人","CURRENT_OPER_NAME"}, {"当前处理人号码","CURRENT_OPER_MOBILE"}, {"归档时间","FINISH_DATE_SHOW"}, {"环节名称","TASK_NAME"}, {"回复人号码","ROUTE_OPER_MOBILE"}, {"回复人名称","ROUTE_OPER_NAME"}, {"回复时间","DEAL_DATE_SHOW"}, {"回复内容","DEAL_CONTENT"}}; //开始输出 HSSFWorkbook wb = new HSSFWorkbook();//定义一个excel HSSFFont headFont = wb.createFont(); headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headFont.setColor(HSSFColor.BLACK.index); headFont.setFontName("微软雅黑"); headFont.setFontHeightInPoints((short)10); HSSFCellStyle headStyle = wb.createCellStyle(); headStyle.setFont(headFont); headStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); HSSFFont bodyFont = wb.createFont(); bodyFont.setColor(HSSFColor.BLACK.index); bodyFont.setFontName("微软雅黑"); bodyFont.setFontHeightInPoints((short)9); HSSFCellStyle bodyCell = wb.createCellStyle(); bodyCell.setFont(bodyFont); bodyCell.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); bodyCell.setAlignment(HSSFCellStyle.ALIGN_LEFT); bodyCell.setBorderBottom(HSSFCellStyle.BORDER_THIN); bodyCell.setBorderLeft(HSSFCellStyle.BORDER_THIN); bodyCell.setBorderTop(HSSFCellStyle.BORDER_THIN); bodyCell.setBorderRight(HSSFCellStyle.BORDER_THIN); HSSFSheet sheet = wb.createSheet("Sheet1"); HSSFCell cell = null; /********************************输出第一行合并表头 begin**************************************/ HSSFRow row = sheet.createRow((short) 0); for (int i = 0; i < map.length; i++) { cell = row.createCell((short)i); cell.setCellStyle(headStyle); cell.setCellValue(new HSSFRichTextString(map[i][0])); } /********************************输出第一行合并表头 end**************************************/ /********************************输出数据列表 begin**************************************/ for (int i = 0; i < exportList.size(); i++) { row = sheet.createRow((short) (i+1)); Map<String, Object> exportMap = exportList.get(i); for (int j = 0; j < map.length; j++) { cell = row.createCell((short)j); cell.setCellStyle(bodyCell); cell.setCellValue(new HSSFRichTextString(str.get(exportMap, map[j][1]))); } } String file_name = new DateHelper().getToday("yyyyMMddHHmmss") + ".xls"; //导出excel String path = "D:\\test\\" + file_name; BufferedOutputStream bos = null; BufferedInputStream bis = null; try { FileOutputStream fout = new FileOutputStream(path); wb.write(fout); fout.close(); //fileUrl = java.net.URLEncoder.encode(fileUrl, "UTF-8"); HttpServletResponse response = this.getResponse(); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("倒三角.xls", "UTF-8")); bis = new BufferedInputStream(new java.io.FileInputStream(path)); bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[1024]; int bytesRead; while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead); } } catch (Exception e) { } finally { try { bis.close(); bos.close(); } catch (Exception e) { } }
02 poi导致中文excel
最新推荐文章于 2024-09-12 14:20:23 发布