Easypoi 导出excel 使用注解实现一二级标题行的单元格合并
先看一下最终效果图
上代码
Excel 模板实体类
@Data
public class HxAdvisoryZJEndExcel {
@Excel(name = "序号",orderNum="0")
private Integer num;
@Excel(name = "项目名称",groupName = "项目",orderNum="1")
private String projectName;
@Excel(name = "项目类型",replace = {"评估咨询_1", "项目咨询_0"},groupName = "项目",orderNum="2")
private String projectType;
@Excel(name = "服务类型",groupName = "项目",orderNum="3")
private String serviceType;
@Excel(name = "委托单位",groupName = "项目",orderNum="4")
private String ownerUnit;
@Excel(name = "投资金额(万元)",groupName = "项目",orderNum="5", numFormat = "#.##")
private BigDecimal investmentAmount;
@Excel(name = "合同收入(元)",groupName = "收入",orderNum="6", numFormat = "#.##")
private BigDecimal contractIncome;
@Excel(name = "实际收入(元)",groupName = "收入",orderNum="7", numFormat = "#.##")
private BigDecimal realIncome;
@Excel(name = "不含税金额",groupName = "收入",orderNum="8", numFormat = "#.##")
private BigDecimal noTaxes;
@Excel(name = "开票时间",groupName = "收入",orderNum="9", format = "yyyy-MM-dd")
private Date makeInvoiceTime;
@Excel(name = "发票号",groupName = "收入",orderNum="10")
private String invoiceCode;
@Excel(name = "评审费",groupName = "支出",orderNum="11", numFormat = "#.##")
private BigDecimal reviewFee;
@Excel(name = "会议费",groupName = "支出",orderNum="12", numFormat = "#.##")
private BigDecimal meetingFee;
@Excel(name = "差旅费",groupName = "支出",orderNum="13", numFormat = "#.##")
private BigDecimal travelFee;
@Excel(name = "经营费",groupName = "支出",orderNum="14", numFormat = "#.##")
private BigDecimal manageFee;
@Excel(name = "其他",groupName = "支出",orderNum="15", numFormat = "#.##")
private String other;
}
关键参数 groupName
例如:
合同收入,实际收入,不含税金额,开票时间,发票号 这些是模板中的字段
他们的 groupName 属性都是 ‘收入’ 则会自动创建收入单元格
注: 一定要有一个字段不标注 groupName 属性,比如上图的 序号字段;
orderNum 属性为标题列的 显示顺序