Skip to content

Commit 3d44e0e

Browse files
committed
Fix on the readValue(Class<?> type) method which incorrectly returned date and numeric values if the wrong type was supplied
1 parent 7249bd8 commit 3d44e0e

File tree

1 file changed

+6
-6
lines changed
  • src/main/java/io/github/mbenincasa/javaexcelutils/model/excel

1 file changed

+6
-6
lines changed

src/main/java/io/github/mbenincasa/javaexcelutils/model/excel/ExcelCell.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,32 @@ public Object readValue(Class<?> type) throws ReadValueException {
110110
default -> throw new ReadValueException("This type '" + type + "' is either incompatible with the CellType '" + this.cell.getCellType() + "'");
111111
}
112112
} else if (Integer.class.equals(type)) {
113-
if (this.cell.getCellType() == CellType.NUMERIC) {
113+
if (this.cell.getCellType() == CellType.NUMERIC && !DateUtil.isCellDateFormatted(this.cell)) {
114114
return (int) this.cell.getNumericCellValue();
115115
}
116116
throw new ReadValueException("This type '" + type + "' is either incompatible with the CellType '" + this.cell.getCellType() + "'");
117-
} else if (Double.class.equals(type)) {
117+
} else if (Double.class.equals(type) && !DateUtil.isCellDateFormatted(this.cell)) {
118118
if (this.cell.getCellType() == CellType.NUMERIC) {
119119
return this.cell.getNumericCellValue();
120120
}
121121
throw new ReadValueException("This type '" + type + "' is either incompatible with the CellType '" + this.cell.getCellType() + "'");
122122
} else if (Long.class.equals(type)) {
123-
if (this.cell.getCellType() == CellType.NUMERIC) {
123+
if (this.cell.getCellType() == CellType.NUMERIC && !DateUtil.isCellDateFormatted(this.cell)) {
124124
return (long) this.cell.getNumericCellValue();
125125
}
126126
throw new ReadValueException("This type '" + type + "' is either incompatible with the CellType '" + this.cell.getCellType() + "'");
127127
} else if (Date.class.equals(type)) {
128-
if (this.cell.getCellType() == CellType.NUMERIC) {
128+
if (this.cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(this.cell)) {
129129
return this.cell.getDateCellValue();
130130
}
131131
throw new ReadValueException("This type '" + type + "' is either incompatible with the CellType '" + this.cell.getCellType() + "'");
132132
} else if (LocalDateTime.class.equals(type)) {
133-
if (this.cell.getCellType() == CellType.NUMERIC) {
133+
if (this.cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(this.cell)) {
134134
return this.cell.getLocalDateTimeCellValue();
135135
}
136136
throw new ReadValueException("This type '" + type + "' is either incompatible with the CellType '" + this.cell.getCellType() + "'");
137137
} else if (LocalDate.class.equals(type)) {
138-
if (this.cell.getCellType() == CellType.NUMERIC) {
138+
if (this.cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(this.cell)) {
139139
return this.cell.getLocalDateTimeCellValue().toLocalDate();
140140
}
141141
throw new ReadValueException("This type '" + type + "' is either incompatible with the CellType '" + this.cell.getCellType() + "'");

0 commit comments

Comments
 (0)