导入处理无数据的单元格,记录所有有数据的单元格及下标,最后将无数据的单元格根据下标补全。
This commit is contained in:
@@ -8,7 +8,9 @@ import java.sql.SQLException;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
@@ -32,6 +34,8 @@ import org.xml.sax.SAXException;
|
|||||||
import org.xml.sax.XMLReader;
|
import org.xml.sax.XMLReader;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
|
import com.nis.util.StringUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用CVS模式解决XLSX文件,可以有效解决用户模式内存溢出的问题
|
* 使用CVS模式解决XLSX文件,可以有效解决用户模式内存溢出的问题
|
||||||
@@ -102,6 +106,7 @@ public abstract class XLSXCovertCSVReader {
|
|||||||
// The last column printed to the output stream
|
// The last column printed to the output stream
|
||||||
private int lastColumnNumber = -1;
|
private int lastColumnNumber = -1;
|
||||||
private List<Object> rowlist = new ArrayList<Object>();
|
private List<Object> rowlist = new ArrayList<Object>();
|
||||||
|
private Map<Integer,Object> rowMap = new HashMap<Integer, Object>();
|
||||||
// Gathers characters as they are seen.
|
// Gathers characters as they are seen.
|
||||||
private StringBuffer value;
|
private StringBuffer value;
|
||||||
// private String[] record;
|
// private String[] record;
|
||||||
@@ -128,6 +133,7 @@ public abstract class XLSXCovertCSVReader {
|
|||||||
this.nextDataType = xssfDataType.NUMBER;
|
this.nextDataType = xssfDataType.NUMBER;
|
||||||
this.formatter = new DataFormatter();
|
this.formatter = new DataFormatter();
|
||||||
rowlist.clear();// 每次读取都清空行集合
|
rowlist.clear();// 每次读取都清空行集合
|
||||||
|
rowMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -287,6 +293,7 @@ public abstract class XLSXCovertCSVReader {
|
|||||||
int len = countNullCell(refnum, preRefnum);
|
int len = countNullCell(refnum, preRefnum);
|
||||||
for(int i=0;i<len;i++){
|
for(int i=0;i<len;i++){
|
||||||
rowlist.add(curCol, "");
|
rowlist.add(curCol, "");
|
||||||
|
rowMap.put(thisColumn, "");
|
||||||
curCol++;
|
curCol++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,6 +305,7 @@ public abstract class XLSXCovertCSVReader {
|
|||||||
}
|
}
|
||||||
// System.out.println("refnum="+refnum+"preRefnum="+preRefnum+"curCol="+curCol);
|
// System.out.println("refnum="+refnum+"preRefnum="+preRefnum+"curCol="+curCol);
|
||||||
rowlist.add(curCol, thisVal);
|
rowlist.add(curCol, thisVal);
|
||||||
|
rowMap.put(thisColumn, thisVal);
|
||||||
rowData.add(new IndexValue(refnum,lastContents) );
|
rowData.add(new IndexValue(refnum,lastContents) );
|
||||||
curCol++;
|
curCol++;
|
||||||
// record[thisColumn] = thisStr;
|
// record[thisColumn] = thisStr;
|
||||||
@@ -324,15 +332,22 @@ public abstract class XLSXCovertCSVReader {
|
|||||||
int len = countNullCell(maxRefnum, refnum);
|
int len = countNullCell(maxRefnum, refnum);
|
||||||
for(int i=0;i<=len;i++){
|
for(int i=0;i<=len;i++){
|
||||||
rowlist.add(curCol, "");
|
rowlist.add(curCol, "");
|
||||||
|
//rowMap.put(thisColumn, "");
|
||||||
curCol++;
|
curCol++;
|
||||||
}
|
}
|
||||||
int totalLen= countTotalCell(maxRefnum);
|
int totalLen= countTotalCell(maxRefnum);
|
||||||
if(rowlist.size()<totalLen) {
|
if(rowlist.size()<totalLen) {
|
||||||
List<Object> tempList=new ArrayList<>(totalLen);
|
List<Object> tempList=new ArrayList<>(totalLen);
|
||||||
for(int i=0;i<(totalLen-rowlist.size());i++) {
|
//修改某一个单元格为空,字段映射顺序错乱问题
|
||||||
tempList.add("");
|
for(int i=0;i<totalLen;i++) {
|
||||||
|
if(!StringUtil.isEmpty(rowMap.get(i))){
|
||||||
|
tempList.add(rowMap.get(i));
|
||||||
|
}else{
|
||||||
|
tempList.add(i,"");
|
||||||
}
|
}
|
||||||
tempList.addAll(rowlist);
|
|
||||||
|
}
|
||||||
|
//tempList.addAll(rowlist);
|
||||||
rowlist= tempList;
|
rowlist= tempList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,6 +358,7 @@ public abstract class XLSXCovertCSVReader {
|
|||||||
optRows(sheetIndex,lastColumnNumber,rowlist);
|
optRows(sheetIndex,lastColumnNumber,rowlist);
|
||||||
|
|
||||||
rowlist.clear();
|
rowlist.clear();
|
||||||
|
rowMap.clear();
|
||||||
// rows.add(record.clone());
|
// rows.add(record.clone());
|
||||||
isCellNull = false;
|
isCellNull = false;
|
||||||
// for (int i = 0; i < record.length; i++) {
|
// for (int i = 0; i < record.length; i++) {
|
||||||
@@ -352,6 +368,7 @@ public abstract class XLSXCovertCSVReader {
|
|||||||
}
|
}
|
||||||
rowlist.clear();
|
rowlist.clear();
|
||||||
rowData.clear();
|
rowData.clear();
|
||||||
|
rowMap.clear();
|
||||||
curCol = 0;
|
curCol = 0;
|
||||||
preRefnum = null;
|
preRefnum = null;
|
||||||
refnum = null;
|
refnum = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user