导出表格头标签为纵向的Excel表格
1、service层
@Transactional(readOnly = true)
public HSSFWorkbook projectExports(Integer curPage, Integer perPageSum, Integer projectId, String schemaId,
HttpServletResponse response) throws InterruptedException, ExecutionException, Exception {
// 分页
Page page = new Page();
page.setCurPage(curPage);
page.setPerPageSum(perPageSum);
RowBounds rowBounds = new RowBounds(page.getNextPage(), page.getPerPageSum());
//获取多租户信息
Users user = new Users();
user.setSchemaId(schemaId);
HSSFWorkbook workbook = new HSSFWorkbook();// 创建一个Excel文件
// 样式设置
HSSFCellStyle columnHeadStyle = (HSSFCellStyle) workbook.createCellStyle();
columnHeadStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 背景
columnHeadStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); // 背景色
columnHeadStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
columnHeadStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
columnHeadStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
columnHeadStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
columnHeadStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
// 全局样式设置
HSSFCellStyle allStyle = (HSSFCellStyle) workbook.createCellStyle();
columnHeadStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 背景
allStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());// 填充白色
allStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
allStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
allStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
allStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
HSSFSheet sheet = workbook.createSheet("项目详情");// 创建一个Excel的Sheet
ProjectDetailDto projectDetailDto = this.projectService.queryDetail(projectId, user);// 创建对象
HSSFRow row0 = sheet.createRow(0);// 创建第一行
HSSFCell cel0_1 = row0.createCell(0);// 创建第一行第一列
cel0_1.setCellValue(new HSSFRichTextString("项目名称"));
cel0_1.setCellStyle(columnHeadStyle);
HSSFCell cel0_2 = row0.createCell(1);// 创建第一行第二列
cel0_2.setCellValue(new HSSFRichTextString(projectDetailDto.getName()));
cel0_2.setCellStyle(allStyle);
HSSFCell cel0_3 = row0.createCell(2);
cel0_3.setCellStyle(allStyle);
HSSFCell cel0_4 = row0.createCell(3);
cel0_4.setCellStyle(allStyle);
HSSFCell cel0_5 = row0.createCell(4);
cel0_5.setCellStyle(allStyle);
HSSFRow row1 = sheet.createRow(1); // 创建第二行
HSSFCell cell1_1 = row1.createCell(0); // 第二行第一列
cell1_1.setCellValue(new HSSFRichTextString("客户名称"));
cell1_1.setCellStyle(columnHeadStyle);
HSSFCell cell1_2 = row1.createCell(1); // 第二行 第二列
cell1_2.setCellValue(new HSSFRichTextString(projectDetailDto.getCustomer