2.ExcelSheet
查看代码 package com.***.excel;import lombok.Data;import java.util.List;/** * @description: 导出多个sheet表 * @author: *** * @date: 2022/9/15 */@Datapublic class ExcelSheet { /*** sheet的名称*/ private String fileName; /*** sheet里的标题*/ private String[] handers; /*** sheet里的数据集*/ private List<String[]> dataset; public ExcelSheet(String fileName, String[] handers, List<String[]> dataset) { this.fileName = fileName; this.handers = handers; this.dataset = dataset; }} 三、相关业务代码1.service层
【二 Java之POI导出Excel:多个sheet】/*** 导出开票及运单信息*/ExportInvoiceAndBillVo exportInvoiceAndBillInfo(InvoiceReviewListDto dto);2.impl实现类
实现类里的代码,需要各位根据自己的业务场景进行改动,无非就是将需要导出的数据先查出来,带入模板中,调用工具类的方法导出 。
查看代码 package com.***.vo.invoicereview;import lombok.Data;import java.io.Serializable;import java.util.List;/** * @description: 导出开票和运单信息Vo * @author: *** * @date: 2022/9/19 */@Datapublic class ExportInvoiceAndBillVo implements Serializable { /*** 开票信息*/ private List<String[]> invoiceList; /*** 运单信息*/ private List<String[]> billList;} 查看代码 @Override public ExportInvoiceAndBillVo exportInvoiceAndBillInfo(InvoiceReviewListDto dto) { ExportInvoiceAndBillVo invoiceAndBill = new ExportInvoiceAndBillVo(); // 查询需要导出的开票信息 PageInfo<InvoiceReviewListVo> pageInfo = queryInvoiceReviewList(dto); List<InvoiceReviewListVo> invoiceList = pageInfo.getList(); if (invoiceList.size() > 10000) { throw new ServiceException("开票数据过多,请分批次导出"); } // 查询需要导出的车运运单信息 List<Long> invoiceIdList = invoiceList.stream().map(InvoiceReviewListVo::getInvoiceId).collect(Collectors.toList()); List<ExportBillVo> billList = getBillInfo(invoiceIdList); if (billList.size() > 10000) { throw new ServiceException("运单数据过多,请分批次导出"); } // 将表1 表2的数据 放入定义的对象Vo中 invoiceAndBill.setInvoiceList(getInvoiceDataList(invoiceList)); invoiceAndBill.setBillList(getBillDataList(billList)); return invoiceAndBill; }
经验总结扩展阅读
-
-
-
12岁小学生身高1.9米被高校选中,体育局:征求过本人和家人意见,她1.86米的姐姐也被选中
-
-
-
-
-
-
丝绸|赵薇又在散发魅力,43岁“挑战”丝绸衣,光腿配鱼嘴鞋更有女人味
-
-
-
-
-
-
-
-
“离婚|“离婚,我不伺候你一家6口”3个侄子的到来,直接毁了8年的婚姻
-
-
-