From 4e0048f818c452bb9ad1d04878200f65e6ba5945 Mon Sep 17 00:00:00 2001 From: zhy Date: Fri, 1 Apr 2022 11:45:33 +0800 Subject: [PATCH] =?UTF-8?q?excel=E5=AF=BC=E5=85=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E5=90=8D=E5=AD=97=E9=87=8D=E5=A4=8D=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E9=87=8D=E5=A4=8D=E5=AD=97=E6=AE=B5=E2=80=9D=E5=A4=87?= =?UTF-8?q?=E6=B3=A8=E2=80=9C=E6=9C=89=E4=B8=A4=E4=B8=AA=EF=BC=8C=E5=88=99?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E4=B8=AD=E5=AF=B9=E5=BA=94=E7=9A=84=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E4=B8=AA=E5=B0=B1=E6=98=AF@Excel(name=20=3D=20"?= =?UTF-8?q?=E5=A4=87=E6=B3=A82")=EF=BC=8C=E6=94=AF=E6=8C=81=E5=A4=9A?= =?UTF-8?q?=E7=BA=A7=E8=A1=A8=E5=A4=B4=E8=AF=BB=E5=8F=96=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=EF=BC=8C=E5=90=8D=E5=AD=97=E4=B8=BA=E6=95=B0=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/poi/ExcelUtil.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index 9a837c430..ee87929c4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -261,13 +261,33 @@ public class ExcelUtil Map cellMap = new HashMap(); // 获取表头 Row heard = sheet.getRow(titleNum); + int nullIndex = 1; for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) { Cell cell = heard.getCell(i); if (StringUtils.isNotNull(cell)) { String value = this.getCellValue(heard, i).toString(); - cellMap.put(value, i); + // 处理表中重复字段标题 + if (cellMap.get(value) != null) + { + int repeat = 1; + do + { + repeat++; + } while(cellMap.get(value + repeat) != null); + cellMap.put(value + repeat, i); + } + else + { + cellMap.put(value, i); + } + // 处理多级表头为空的段落 + if (StringUtils.isEmpty(value)) + { + cellMap.put(nullIndex + "", i); + nullIndex++; + } } else {