3
@Override
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
if(CellDataTypeEnum.IMAGE.equals(cellData.getType())){
log.info("第{}行,第{}列数据转换后。{}", cell.getRowIndex(), cell.getColumnIndex(),cellData.getType());
Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
Sheet sheet = workbook.getSheetAt(0);
//画图的顶级管理器,一个sheet只能获取一个(一定要注意这点)
Drawing patriarch = sheet.createDrawingPatriarch();
//anchor主要用于设置图片的属性
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 255, 255, cell.getColumnIndex(), cell.getRowIndex()+1, cell.getColumnIndex()+2, cell.getRowIndex()+6);
anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
//插入图片
patriarch.createPicture(anchor, workbook.addPicture(cellData.getImageValue(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
// 这里可以对cell进行任何操作
//log.info("第{}行,第{}列写入完成。{}", cell.getRowIndex(), cell.getColumnIndex(),cell.getCellType());
}
建议描述 在afterCellDataConverted中处理,是图片类型时,手动写图片到模板中,并设置大小。有个问题就是,这个不会覆盖easyexcel图片写入,导致图片重复写入。 如果说是在afterCellDispose中设置图片大小,该怎么操作。