From 13956040933ffda6aa9e0415097881327a9379f8 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Fri, 30 Aug 2019 13:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A9=BA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E8=AF=BB=E5=8F=96=E5=8F=AF=E8=83=BD=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E4=B8=8A=E4=B8=AA=E5=AD=97=E6=AE=B5=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excel/analysis/v03/XlsSaxAnalyser.java | 1 + .../v07/handlers/DefaultCellHandler.java | 2 ++ .../com/alibaba/excel/metadata/CellData.java | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java b/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java index 2b67b43..a5072a1 100644 --- a/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java +++ b/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java @@ -131,6 +131,7 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelExecutor { thisColumn = handler.getColumn(); cellData = handler.getCellData(); if (cellData != null) { + cellData.checkEmpty(); records.put(thisColumn, cellData); } break; diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java index 671693b..0ee8ab3 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java @@ -120,6 +120,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder } else if (currentCellData.getType() == CellDataTypeEnum.DIRECT_STRING) { currentCellData.setType(CellDataTypeEnum.STRING); } + currentCellData.checkEmpty(); curRowContent.put(curCol, currentCellData); } // This is a special form of string @@ -130,6 +131,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder stringValue = stringValue.trim(); } currentCellData.setStringValue(stringValue); + currentCellData.checkEmpty(); curRowContent.put(curCol, currentCellData); } } diff --git a/src/main/java/com/alibaba/excel/metadata/CellData.java b/src/main/java/com/alibaba/excel/metadata/CellData.java index db73ce8..adfb091 100644 --- a/src/main/java/com/alibaba/excel/metadata/CellData.java +++ b/src/main/java/com/alibaba/excel/metadata/CellData.java @@ -168,6 +168,31 @@ public class CellData { this.dataFormatString = dataFormatString; } + /** + * Ensure that the object does not appear null + */ + public void checkEmpty() { + switch (type) { + case STRING: + case ERROR: + if (stringValue == null) { + type = CellDataTypeEnum.EMPTY; + } + return; + case NUMBER: + if (doubleValue == null) { + type = CellDataTypeEnum.EMPTY; + } + return; + case BOOLEAN: + if (booleanValue == null) { + type = CellDataTypeEnum.EMPTY; + } + return; + default: + } + } + @Override public String toString() { switch (type) {