This commit is contained in:
Looly 2023-05-26 21:49:47 +08:00
parent 8ea3748b6f
commit 458c38e421
3 changed files with 13 additions and 11 deletions

View File

@ -44,9 +44,13 @@ import java.io.InputStream;
*/
public class ExcelSaxUtil {
// 填充字符串
/**
* 填充字符串
*/
public static final char CELL_FILL_CHAR = '@';
// 列的最大位数
/**
* 列的最大位数
*/
public static final int MAX_CELL_BIT = 3;
/**
@ -103,13 +107,6 @@ public class ExcelSaxUtil {
result = value;
}
break;
case NUMBER:
try {
result = getNumberValue(value, numFmtString);
} catch (final NumberFormatException e) {
result = value;
}
break;
case DATE:
try {
result = getDateValue(value);
@ -118,7 +115,11 @@ public class ExcelSaxUtil {
}
break;
default:
result = value;
try {
result = getNumberValue(value, numFmtString);
} catch (final NumberFormatException e) {
result = value;
}
break;
}
return result;

View File

@ -267,6 +267,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
value = new FormulaCellValue(StrUtil.trim(lastFormula),
ExcelSaxUtil.getDataValue(this.cellDataType, contentStr, this.sharedStrings, this.numFmtString));
}else{
// since 6.0.0默认的cellDataType是NULL而非NUMBER
value = ExcelSaxUtil.getDataValue(this.cellDataType, contentStr, this.sharedStrings, this.numFmtString);
}
addCellValue(curCell++, value);

View File

@ -204,7 +204,7 @@ public class ExcelSaxReadTest {
// 非日期格式不做转换
Assertions.assertEquals("112233", rows.get(2));
// 读取实际值而非带有格式处理过的值
Assertions.assertEquals("1000", rows.get(3));
Assertions.assertEquals("1000.0", rows.get(3));
Assertions.assertEquals("2012-12-21 00:00:00", rows.get(4));
}