From a24cbd89ba6e8d7c552d64f2b1657a2a20d7c05f Mon Sep 17 00:00:00 2001 From: guoshengxiong <1923636941@qq.com> Date: Thu, 25 Sep 2025 10:32:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=9B=BE=E7=89=87=E5=88=B0ex?= =?UTF-8?q?cel=20bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/zhgd/xmgl/util/ExcelUtils.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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; }