提交 c22b8898 authored 作者: taojinlong's avatar taojinlong

fix: 解析 excel 报错

上级 db8c0412
...@@ -23,6 +23,8 @@ import org.xml.sax.helpers.XMLReaderFactory; ...@@ -23,6 +23,8 @@ import org.xml.sax.helpers.XMLReaderFactory;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* @author y * @author y
...@@ -252,6 +254,13 @@ public class ExcelXlsxReader extends DefaultHandler { ...@@ -252,6 +254,13 @@ public class ExcelXlsxReader extends DefaultHandler {
String value = this.getDataValue(lastIndex.trim(), "");//根据索引值获取对应的单元格值 String value = this.getDataValue(lastIndex.trim(), "");//根据索引值获取对应的单元格值
if (preRef == null) { if (preRef == null) {
String regEx="[^0-9]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(ref);
if(curCol < Integer.valueOf(m.replaceAll("").trim()) -1 ){
cellList.add(curCol, "");
curCol++;
}
preRef = ref; preRef = ref;
} }
//补全单元格之间的空单元格 //补全单元格之间的空单元格
...@@ -260,12 +269,16 @@ public class ExcelXlsxReader extends DefaultHandler { ...@@ -260,12 +269,16 @@ public class ExcelXlsxReader extends DefaultHandler {
}else if (!ref.equals(preRef)) { }else if (!ref.equals(preRef)) {
int len = countNullCell(ref, preRef); int len = countNullCell(ref, preRef);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
cellList.add(curCol, ""); if(curCol < this.fields.size()){
curCol++; cellList.add(curCol, "");
curCol++;
}
} }
} }
cellList.add(curCol, value); if(curCol < this.fields.size()){
cellList.add(curCol, value);
}
curCol++; curCol++;
//如果里面某个单元格含有值,则标识该行不为空行 //如果里面某个单元格含有值,则标识该行不为空行
if (value != null && !"".equals(value)) { if (value != null && !"".equals(value)) {
...@@ -418,6 +431,9 @@ public class ExcelXlsxReader extends DefaultHandler { ...@@ -418,6 +431,9 @@ public class ExcelXlsxReader extends DefaultHandler {
if(CollectionUtils.isEmpty(this.getFields())){ if(CollectionUtils.isEmpty(this.getFields())){
throw new RuntimeException(Translator.get("i18n_excel_header_empty")); throw new RuntimeException(Translator.get("i18n_excel_header_empty"));
} }
if(curCol >= this.fields.size()){
return thisStr;
}
if(curRow==2){ if(curRow==2){
this.getFields().get(curCol).setFieldType(type); this.getFields().get(curCol).setFieldType(type);
}else { }else {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论