今天使用poi解析Excel的时候遇到一个错误,记录一下
: null
at .check_dated(:1274)
at (:1529)
at (:491)
at (:469)
at (:4646)
at (:929)
at (:916)
at (:57)
at (:75)
at (:366)
at $$FastClassBySpringCGLIB$$(<generated>)
at (:218)
at $(:684)
at $$EnhancerBySpringCGLIB$$(<generated>)
at .invoke0(Native Method)
at (:62)
at (:43)
at (:498)
at (:190)
at (:138)
at (:104)
at (:892)
at (:797)
at (:87)
at (:1039)
at (:942)
at (:1005)
at (:908)
at (:660)
at (:882)
at (:741)
at (:231)
at (:166)
at (:53)
at (:193)
at (:166)
at (:61)
at (:108)
at (:137)
at (:125)
at (:66)
at (:108)
at (:137)
at (:125)
at (:66)
at (:449)
at $(:365)
at (:90)
at (:83)
at (:387)
at (:362)
at (:125)
at (:193)
at (:166)
at .(:53)
at (:193)
at (:166)
at .(:90)
at (:193)
at (:166)
at (:123)
at (:193)
at (:166)
at (:200)
at (:109)
at (:193)
at (:166)
at (:202)
at (:96)
at (:490)
at (:139)
at (:92)
at (:74)
at (:343)
at .http11.(:408)
at (:66)
at $(:853)
at $(:1587)
at (:49)
at (:1149)
at $(:624)
at $(:61)
at (:748)
这个问题很奇怪,把表格内容复制一份到其他sheet或者复制到其他表格重新解析,它又很神奇的好了,这个也是个很大的坑。
贴一下我解决的工具类代码
public static String getCellStringValue(Cell cell) {
CellType cellType = ();
if (()!= 1) {
();
}
String stringCellValue = ().trim();
if(stringCellValue!=null)return stringCellValue;
switch (()) {
case BOOLEAN:
return () ? "TRUE" : "FALSE";
case FORMULA:
try {
String result = (());
if ((".0")) {
String[] strs = ("\\.0");
result = strs[0];
}
return result;
} catch (IllegalStateException e) {
try {
return (());
} catch (Exception e1) {
return ();
}
}
case NUMERIC:
();
return ();
case STRING:
String result = ().getString(); //();
try {
// 常规的字符串类型有时会被误判为百分比形式的,所以放到try里面
String style = ().getDataFormatString();
if(("%") == -1) {
String pattern = "\\d{" + () + "}";
Matcher matcher = (pattern).matcher(result);
if(("0") && ()) {
return result;
}
}
if(!("[a-zA-Z]").matcher(result).find()) {
// 对于有些cell中是常规类型的数字,但是会被解析成double类型变成科学计数法
DecimalFormat df = new DecimalFormat("####################.####################");
result = ((result));
}
// 常规的字符串类型有时会被误判为百分比形式的,所以放到try里面
if (("%") != -1) {
result = ((result)*100) + "%";
}
} catch (Exception e) {
//(());
//((), e);
}
return result;
default:
return ""; // 如果什么都没有,就返回空值。
}
}