图片导出
模板图片导出,没有注解导出图片那么容易,但也不算复杂,构建一个ImageEntity 设置下高宽,地址或者byte[]就可以了
ImageEntity image = new ImageEntity();
image.setHeight(200);
image.setWidth(500);
image.setUrl("imgs/company/baidu.png");
具体的导出代码
@Test
public void one() throws Exception {
TemplateExportParams params = new TemplateExportParams(
"doc/exportTemp_image.xls", true);
Map<String, Object> map = new HashMap<String, Object>();
// sheet 2
map.put("month", 10);
Map<String, Object> temp;
for (int i = 1; i < 8; i++) {
temp = new HashMap<String, Object>();
temp.put("per", i * 10);
temp.put("mon", i * 1000);
temp.put("summon", i * 10000);
ImageEntity image = new ImageEntity();
image.setHeight(200);
image.setWidth(500);
image.setUrl("imgs/company/baidu.png");
temp.put("image", image);
map.put("i" + i, temp);
}
Workbook book = ExcelExportUtil.exportExcel(params, map);
File savefile = new File("D:/excel/");
if (!savefile.exists()) {
savefile.mkdirs();
}
FileOutputStream fos = new FileOutputStream("D:/excel/exportTemp_image.xls");
book.write(fos);
fos.close();
}