导出EXCEL合并单元格
最后更新:2024-05-23 14:51:32
|
状态:未完成
数据是这样
模板是这样
导出后是这样
DataSet set = new DataSet(); DataRow row = new DataRow(); row.put("Y","2020"); row.put("M","1"); row.put("D","1"); set.add(row); DataRow row2 = new DataRow(); row2.put("Y","2020"); row2.put("M","1"); row2.put("D","2"); set.add(row2); DataRow row3 = new DataRow(); row3.put("Y","1999"); row3.put("M","1"); row3.put("D", null); set.add(row3); set.replaceEmpty("/");//替换空值的数据 TableBuilder builder = TableBuilder.init() .setDatas(set)//设置数据源 .setFields("Y","M","D")//设置需要导出的属性(列) .addUnion("Y","M(Y)");//设置需要合并行的列,如果年相同的合并,月相同的合并(前提是年相同) File file = new File("模板地址"); ExcelUtil.export(file, "sheet名称", 2, builder.build()); //从第2行插入(根据表头行数) System.out.println(builder.build().build()); //看一下输入对应的html 参考【示例源码】