@RequestMapping(value = "exportExcel") public void exportExcel(BizUserArchive bizUserArchive,HttpServletRequest request, HttpServletResponse response) { // bizUserArchiveService.export2ExcelInfo(request, response); HSSFWorkbook wb = new HSSFWorkbook();//创建excle HSSFSheet sheet = wb.createSheet("new sheet");//创建sheet工作表对象(编号从0开始) HSSFCellStyle style = wb.createCellStyle(); // 样式对象 style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直样式 style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平样式 // 设置字体 HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 36);// 字体大小 //列宽 sheet.setColumnWidth(0, 3000); sheet.setColumnWidth(1, 3500); bizUserArchive = bizUserArchiveService.loadArchiveByUserId(bizUserArchive); HSSFRow row0 = sheet.createRow((short) 0);//第一行 row0.setHeight((short) 500); // 行高 HSSFCell cell0 = row0.createCell(0); //第一行第一列 cell0.setCellValue(new HSSFRichTextString("姓名")); HSSFCell cell1 = row0.createCell(1); //第一行第二列 cell1.setCellValue(bizUserArchive.getPersonName()); // loadArchiveByUserId response.setContentType("application/vnd.ms-excel"); OutputStream ouputStream=null;try {ouputStream = response.getOutputStream();wb.write(ouputStream); ouputStream.flush(); ouputStream.close(); } catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} }
HSSFWorkBooK用法 做excle导出excle
最新推荐文章于 2023-12-27 00:28:12 发布