Open bobo930808 opened 1 month ago
@Override public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { // 填充图片 } public void insertImage(Sheet sheet, Cell cell, byte[] pictureData, int i) { int picWidth = Units.pixelToEMU(imageWidth); int index = sheet.getWorkbook().addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG); Drawing<?> drawing = sheet.getDrawingPatriarch(); if (drawing == null) { drawing = sheet.createDrawingPatriarch(); } CreationHelper helper = sheet.getWorkbook().getCreationHelper(); ClientAnchor anchor = helper.createClientAnchor(); /* * 设置图片坐标 * 为了不让图片遮挡单元格的上边框和右边框,故 x1、x2、y1 这几个坐标点均向后移动了一个像素点 */ anchor.setDx1(Units.pixelToEMU(1) + picWidth * i); anchor.setDx2(Units.pixelToEMU(1) + picWidth + picWidth * i); anchor.setDy1(Units.pixelToEMU(1)); anchor.setDy2(0); //设置图片位置 int columnIndex = cell.getColumnIndex(); anchor.setCol1(columnIndex); anchor.setCol2(columnIndex); int rowIndex = cell.getRowIndex(); anchor.setRow1(rowIndex); anchor.setRow2(rowIndex + 1); anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE); drawing.createPicture(anchor, index); } 这里写代码
触发Bug的代码