From cb761ffea2593cd3bfd965c5dff6b868a0bee6e0 Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 15 Oct 2020 18:49:34 +0800 Subject: [PATCH] fix mergeRegion --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/poi/excel/cell/CellUtil.java | 2 +- .../test/java/cn/hutool/poi/excel/test/ExcelReadTest.java | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4728f6010..c281bf50c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ * 【core 】 解决ListUtil计算总量可能的int溢出问题(pr#1150@Github) * 【json 】 解决JSON中转换为double小数精度丢失问题(pr#192@Gitee) * 【core 】 修复CaseInsensitiveMap的remove等方法并没有忽略大小写的问题(pr#1163@Gitee) +* 【poi 】 修复合并单元格值读取错误的问题 ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java index 34b1af790..602c4211c 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java @@ -103,7 +103,7 @@ public class CellUtil { cellType = cell.getCellTypeEnum(); } - if(CellType.BLANK == cellType){ + if(CellType.BLANK == cellType || CellUtil.isMergedRegion(cell)){ // 空白单元格可能为合并单元格 cell = getMergedRegionCell(cell); cellType = cell.getCellTypeEnum(); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java index 95c6d2177..d0e01f7c0 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java @@ -215,9 +215,12 @@ public class ExcelReadTest { } @Test + @Ignore public void readTest() { final ExcelReader reader = ExcelUtil.getReader("d:/test/人员体检信息表.xlsx"); - final List> read = reader.read(); -// Console.log(read); + final List> read = reader.read(2); + for (List list : read) { + Console.log(list); + } } }