先上图

1.引入 …略
2.写模板 excel模板

具体指令
3. 测试
public static void main(String[] args) throws IOException {
List<ExportZYDMYVO> list = new ArrayList<ExportZYDMYVO>();
ExportZYDMYVO i1 = new ExportZYDMYVO();
i1.setOrderNo("scj001");
i1.setOrderTime(Func.formatDateTime(new Date()));
i1.setPlate("鲁A");
i1.setItem(1);
i1.setDrawNum("tu");
i1.setProduct("pro");
i1.setName("name2");
i1.setPlan("jihua");
i1.setNum("10");
i1.setDriverName("张三");
i1.setDriverPhone("1366666666");
i1.setTon(new BigDecimal("11.11"));
i1.setCubes(new BigDecimal("2"));
ExportZYDMYVO i2 = new ExportZYDMYVO();
i2.setItem(2);
i2.setDrawNum("tu");
i2.setProduct("pro");
i2.setName("name2");
i2.setPlan("jihua2");
i2.setNum("120");
i2.setTon(new BigDecimal("11.11"));
i2.setCubes(new BigDecimal("2"));
ExportZYDMYVO i3 = new ExportZYDMYVO();
i3.setItem(3);
i3.setDrawNum("tu");
i3.setProduct("pro");
i3.setName("name");
i3.setPlan("jihua2");
i3.setNum("130");
i3.setTon(new BigDecimal("11.11"));
i3.setCubes(new BigDecimal("1.1"));
list.add(i1);
list.add(i2);
list.add(i3);
Map<String, Object> map = new HashMap<String, Object>();
TemplateExportParams params = new TemplateExportParams("static/excelTemplates/装运单.xls");
if (list != null && list.size() > 0) {
map.put("orderNo", list.get(0).getOrderNo());
map.put("orderTime", list.get(0).getOrderTime());
map.put("plate", list.get(0).getPlate());
map.put("driverName", list.get(0).getDriverName());
map.put("driverPhone", list.get(0).getDriverPhone());
}
map.put("list", list);
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
//1.带条件合并(本列值相同 并其他列值也相同)
Map<Integer,int[]> itemMap = new HashMap<Integer,int[]>();
itemMap.put(1, new int[]{}); //参数1:需合并的列 参数2:依赖的列(若此列值相同 并合并列值相同 合并单元格 没有传空)
itemMap.put(6, new int[]{3});
itemMap.put(7, new int[]{3});
//startRow - 开始行 endRow - 结束行
//PoiMergeCellUtil.mergeCells(workbook.getSheetAt(0), itemMap, 3);
PoiMergeCellUtil.mergeCells(workbook.getSheetAt(0), itemMap, 3 ,10);
//2.不带条件合并 (本列值相同)
//PoiMergeCellUtil.mergeCells(workbook.getSheetAt(0), 1, 1, 6, 7);//合并列 startRow:开始合并行 columns:需合并的列 从0开始
// String excelUrl = ParamCache.getValue("upload.file.url");
// String destPath= ParamCache.getValue("upload.image.path");
String fileName = "/ZQMY" + Func.formatDate(new Date()) + map.get("plate") + "装运单.xls";
// File savefile = new File(destPath);
File savefile = new File("D:/excel/");
if (!savefile.exists()) {
savefile.mkdirs();
}
if (workbook != null) {
//FileOutputStream fos = new FileOutputStream(destPath +"/files/"+fileName);
FileOutputStream fos = new FileOutputStream(savefile + fileName);
workbook.write(fos);
fos.close();
}
}