1、背景
这次需求需要用嵌入合并单元格来实现,最终需要生成的excel如下:
在审批流程部分,第一列需要一个标题描述,并且需要合并单元格,后三列列出详细信息。
2、实现方案
2.1 定义数据结构
Context context = new Context();context.putVar("personCID", "111");context.putVar("name", "222");context.putVar("jobName", "挖掘机");List<ApprovalBO> approvalBOList = new ArrayList<>();ApprovalBO approvalBO1 = new ApprovalBO();ApprovalBO approvalBO2 = new ApprovalBO();ApprovalBO approvalBO3 = new ApprovalBO();ApprovalBO approvalBO4 = new ApprovalBO();approvalBO1.setName("审批人");approvalBO1.setEmail("邮箱");approvalBO1.setTime("审批时间");approvalBO1.setOptition("审批意见");approvalBO2.setName("张哈哈");approvalBO2.setEmail("123@456");approvalBO2.setTime("2099-10-32 18:00");approvalBO2.setOptition("同意");approvalBO3.setName("张笑笑");approvalBO3.setEmail("123@456");approvalBO3.setTime("2099-10-32 19:00");approvalBO3.setOptition("不同意");approvalBO4.setName("张哭哭");approvalBO4.setEmail("123@456");approvalBO4.setTime("2099-10-32 20:00");approvalBO4.setOptition("再考虑");approvalBOList.add(approvalBO1);approvalBOList.add(approvalBO2);approvalBOList.add(approvalBO3);approvalBOList.add(approvalBO4);List<OfferFormBO> offerFormBOS = new ArrayList<>();OfferFormBO offerFormBO = new OfferFormBO();offerFormBO.setApprovalBOList(approvalBOList);offerFormBOS.add(offerFormBO);context.putVar("offerFormBOS", offerFormBOS);
其基本结构如下:
{jobName=挖掘机,personCID=111, offerFormBOS=[ OfferFormBO{personCID='null',name='null', jobName='null', approvalBOList=[ ApprovalBO{name='审批人', email='邮箱', time='审 批时间', optition='审批意见'}, ApprovalBO{name='张哈哈', email='123@456', time='2099-10-32 18:00', optition='同意'}, ApprovalBO{name='张笑笑', email='123@456', time='2099-10-32 19:00', optition='不同意'}, ApprovalBO{name='张哭哭', email='123@456', time='2099-10-32 20:00', optition='再考虑'}]}], name=222}
2.2 定义excel模板
2.3 测试效果
项目demo地址:
/zzffox/jXLSdemo.git