Browse Source

修改空字符串读取可能读取上个字段的数据的bug

pull/523/head
Jiaju Zhuang 5 years ago
parent
commit
1395604093
  1. 1
      src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
  2. 2
      src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
  3. 25
      src/main/java/com/alibaba/excel/metadata/CellData.java

1
src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java

@ -131,6 +131,7 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelExecutor {
thisColumn = handler.getColumn(); thisColumn = handler.getColumn();
cellData = handler.getCellData(); cellData = handler.getCellData();
if (cellData != null) { if (cellData != null) {
cellData.checkEmpty();
records.put(thisColumn, cellData); records.put(thisColumn, cellData);
} }
break; break;

2
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) { } else if (currentCellData.getType() == CellDataTypeEnum.DIRECT_STRING) {
currentCellData.setType(CellDataTypeEnum.STRING); currentCellData.setType(CellDataTypeEnum.STRING);
} }
currentCellData.checkEmpty();
curRowContent.put(curCol, currentCellData); curRowContent.put(curCol, currentCellData);
} }
// This is a special form of string // This is a special form of string
@ -130,6 +131,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
stringValue = stringValue.trim(); stringValue = stringValue.trim();
} }
currentCellData.setStringValue(stringValue); currentCellData.setStringValue(stringValue);
currentCellData.checkEmpty();
curRowContent.put(curCol, currentCellData); curRowContent.put(curCol, currentCellData);
} }
} }

25
src/main/java/com/alibaba/excel/metadata/CellData.java

@ -168,6 +168,31 @@ public class CellData {
this.dataFormatString = dataFormatString; 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 @Override
public String toString() { public String toString() {
switch (type) { switch (type) {

Loading…
Cancel
Save