diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java index 0973d7675..cd176e7ac 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java @@ -829,7 +829,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl> imgListAll) throws Exception { + public static void setRowHeight(WorksheetPart worksheetPart, int rIndex, double height, int cIndex, String text) { + SheetData sheetData = worksheetPart.getJaxbElement().getSheetData(); + + org.xlsx4j.sml.Row r = sheetData.getRow().get(rIndex); + if (r.getHt() == null || (r.getHt() != null && r.getHt() < height)) { + r.setHt(height); + r.setCustomHeight(true); + } + + Cell c = r.getC().get(cIndex); + if (text == null) { + c.setV(null); + } + } + + public static void replacePictureBatchPOI(Workbook workbook, SpreadsheetMLPackage pkg, List> imgListAll, HashMap params) throws Exception { //获取全部sheet页中表格 Sheet sheet=null; int partNameNum = 0; @@ -83,6 +98,7 @@ public class ExcelUtil { int totalRowNum = sheet.getLastRowNum(); //获得所有数据 + int k = 0; for (int x = 0; x < totalRowNum; x++) { //获得第x行对象 Row row = sheet.getRow(x); @@ -90,12 +106,14 @@ public class ExcelUtil { //获得总列数 int cellLength = row.getLastCellNum(); //如果x行里的所有单元格 + int j = 0; for (int y = 0; y < cellLength; y++) { org.apache.poi.ss.usermodel.Cell cell = row.getCell(y); if(ObjectUtil.isNull(cell)) { continue; } + String cellValue = cell.getStringCellValue(); for (Map imgMap : imgListAll) { @@ -103,10 +121,23 @@ public class ExcelUtil { String text = (String) imgMap.get("text"); byte[] bytes = (byte[]) imgMap.get("bytes"); if (("${" + key + "}").equals(cellValue)) { + + // 根据图片大小调整行高 + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + BufferedImage bufferedImage = ImageIO.read(in); + setRowHeight(worksheetPart, k, bufferedImage.getHeight(), j, text); + + if (text != null) { + params.put(key, text); + } + + // 插入图片到表格 putImagePOI(worksheetPart, pkg, cell, bytes, sheet.getSheetName().toLowerCase(), String.valueOf(partNameNum)); } } + j++; // 单元格非空才++ } + k++; // 行非空才++ } } @@ -173,7 +204,7 @@ public class ExcelUtil { anchor.getFrom().setCol(newCell.getColumnIndex()); anchor.getFrom().setRow(newCell.getRowIndex()); anchor.setTo(new CTMarker()); - anchor.getTo().setCol(newCell.getColumnIndex() + 1); + anchor.getTo().setCol(newCell.getColumnIndex() + 1); // TODO anchor.getTo().setRow(newCell.getRowIndex() + 1); CTPicture picture = new CTPicture();