fix: 解析 excel 报错
This commit is contained in:
parent
db8c0412db
commit
c22b889846
@ -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 {
|
|||||||
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 {
|
|||||||
}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++) {
|
||||||
|
if(curCol < this.fields.size()){
|
||||||
cellList.add(curCol, "");
|
cellList.add(curCol, "");
|
||||||
curCol++;
|
curCol++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(curCol < this.fields.size()){
|
||||||
cellList.add(curCol, value);
|
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 {
|
|||||||
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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user