/**
* 生成有图片的excel
*
* @param demoDataList 数据列表
* @param fileName 生成文件路径
*/
private void genImageExcel(List<ImageDemoData> demoDataList, String fileName) {
if (CollectionUtils.isEmpty(demoDataList)) {
return;
}
//图片列最大图片数
AtomicReference<Integer> maxImageSize = new AtomicReference<>(0);
demoDataList.forEach(item -> {
if (CollectionUtils.isNotEmpty(item.getImagePathList()) && item.getImagePathList().size() > maxImageSize.get()) {
maxImageSize.set(item.getImagePathList().size());
}
});
//设置列长度所用类
AutoColumnWidthStyleStrategy longWidth = new AutoColumnWidthStyleStrategy();
List<ImageData> imageDataListAll = new ArrayList<>();
demoDataList.forEach(item -> {
WriteCellData<Void> writeCellData = new WriteCellData<>();
if (CollectionUtils.isNotEmpty(item.getImagePathList())) {
//每张图片间距
Integer splitWidth = 2;
//每张图片的长度
Integer imageWidth = 80;
//图片列的最大长度
Integer sumWidth = maxImageSize.get() * (imageWidth + splitWidth);
List<ImageData> imageDataList = new ArrayList<>();
List<String> imagePathList = item.getImagePathList();
for (int i = 1; i <= imagePathList.size(); i++) {
String path = imagePathList.get(i - 1);
Integer left = imageWidth * (i - 1) + i * splitWidth;
Integer right = sumWidth - imageWidth - left;
ImageData imageData = new ImageData();
try {
imageData.setImage(FileUtils.readFileToByteArray(new File(path)));
} catch (IOException e) {
e.printStackTrace();
}
imageData.setImageType(ImageData.ImageType.PICTURE_TYPE_PNG);
//距离单元格顶部距离
imageData.setTop(1);
//距离单元格底部距离
imageData.setBottom(1);
//距离单元格左边距离
imageData.setLeft(left);
//距离单元格右边距离
imageData.setRight(right);
imageData.setAnchorType(ClientAnchorData.AnchorType.DONT_MOVE_DO_RESIZE);
imageDataList.add(imageData);
}
writeCellData.setImageDataList(imageDataList);
imageDataListAll.addAll(imageDataList);
Map<String, Integer> zdyColumnWidth = new HashMap<>();
//图片列名称,对应导出对象的列名称,图片列长度
zdyColumnWidth.put("上传图片", sumWidth / 6);
longWidth.setZdyColumnWidth(zdyColumnWidth);
}
item.setWriteCellDataFile(writeCellData);
});
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(new File("C:\\Users\\JUNSHI\\Desktop\\excelrepeat.xlsx")).build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).build();
excelWriter.fill(new FillWrapper("data", demoDataList), fillConfig, writeSheet);
excelWriter.finish();
}
异常提示 请提供完整的异常提示,记住是全部异常! 建议描述