修复导入excel前列为空时自动补全空列

This commit is contained in:
wangxin
2018-12-18 03:25:21 +06:00
parent f492ec8353
commit 784fee2ab7

View File

@@ -319,16 +319,27 @@ public abstract class XLSXCovertCSVReader {
maxRefnum = refnum;
}
//补全一行尾部可能缺失的单元格
if(maxRefnum != null){
if(maxRefnum != null){
int len = countNullCell(maxRefnum, refnum);
for(int i=0;i<=len;i++){
rowlist.add(curCol, "");
curCol++;
}
}
int totalLen= countTotalCell(maxRefnum);
if(rowlist.size()<totalLen) {
List<Object> tempList=new ArrayList<>(totalLen);
for(int i=0;i<(totalLen-rowlist.size());i++) {
tempList.add("");
}
tempList.addAll(rowlist);
rowlist= tempList;
}
}
if ( rowlist.get(0) != null
&& rowlist.get(1) != null)// 判断是否空行
{
optRows(sheetIndex,lastColumnNumber,rowlist);
rowlist.clear();
@@ -562,6 +573,69 @@ public List<String> getMyDataList(List<IndexValue> dataList) {
int res = (letter[0]-letter_1[0])*26*26 + (letter[1]-letter_1[1])*26 + (letter[2]-letter_1[2]);
return res-1;
}
/**
* 计算两个单元格之间的单元格数目(同一行)
* @param ref
* @param preRef
* @return
*/
public int countTotalCell(String ref){
String xfd = ref.replaceAll("\\d+", "");
if(xfd.equals("A")) {
return 1;
}else if(xfd.equals("B")) {
return 2;
}else if(xfd.equals("C")) {
return 3;
}else if(xfd.equals("D")) {
return 4;
}else if(xfd.equals("E")) {
return 5;
}else if(xfd.equals("F")) {
return 6;
}else if(xfd.equals("G")) {
return 7;
}else if(xfd.equals("H")) {
return 8;
}else if(xfd.equals("I")) {
return 9;
}else if(xfd.equals("J")) {
return 10;
}else if(xfd.equals("K")) {
return 11;
}else if(xfd.equals("L")) {
return 12;
}else if(xfd.equals("M")) {
return 13;
}else if(xfd.equals("N")) {
return 14;
}else if(xfd.equals("O")) {
return 15;
}else if(xfd.equals("P")) {
return 16;
}else if(xfd.equals("Q")) {
return 17;
}else if(xfd.equals("R")) {
return 18;
}else if(xfd.equals("S")) {
return 19;
}else if(xfd.equals("T")) {
return 20;
}else if(xfd.equals("U")) {
return 21;
}else if(xfd.equals("V")) {
return 22;
}else if(xfd.equals("W")) {
return 23;
}else if(xfd.equals("X")) {
return 24;
}else if(xfd.equals("Y")) {
return 25;
}else if(xfd.equals("Z")) {
return 26;
}
return 27;
}
/**
* 字符串的填充
* @param str