java导出excel竖着_Excel导出纵向表格(poi)

导出表格头标签为纵向的Excel表格

4c397fb6f570a26ccd3afab17f1d9f0d.png

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值