diff --git a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java index fac233e5b..43aabbee4 100644 --- a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java @@ -915,12 +915,21 @@ public class ExcelUtils { int colIndex = startCol; for (byte[] bytes : bytesList) { + // 跳过空图片 if (bytes == null || bytes.length == 0) { + // 根据方向调整位置,跳过当前行或列 + if (direction == 1) { + // 纵向排列:向下移动一行 + rowIndex++; + } else { + // 横向排列:向右移动一列 + colIndex++; + } continue; } try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { - // 获取图片格式(简单判断,实际可能需要更复杂的检测) + // 获取图片格式 int pictureType = getPictureType(bytes); // 添加图片到工作簿 @@ -955,7 +964,13 @@ public class ExcelUtils { } } catch (Exception e) { - log.error("", e); + log.error("导出图片失败", e); + // 发生异常时也继续处理下一个图片,但记录错误 + if (direction == 1) { + rowIndex++; + } else { + colIndex++; + } } } } @@ -964,7 +979,7 @@ public class ExcelUtils { * 根据图片字节数组判断图片类型 */ private static int getPictureType(byte[] bytes) { - if (bytes.length < 4) { + if (bytes == null || bytes.length < 4) { return Workbook.PICTURE_TYPE_PNG; }