|
|
|
@ -305,6 +305,23 @@ public class ExcelUtils {
|
|
|
|
|
int rowStart = sheet.getFirstRowNum();
|
|
|
|
|
// 尾行下标
|
|
|
|
|
int rowEnd = sheet.getLastRowNum();
|
|
|
|
|
//行数
|
|
|
|
|
int lastRowNum = sheet.getLastRowNum()+1;
|
|
|
|
|
int row = 0;
|
|
|
|
|
// Row row = sheet.getRow(5);
|
|
|
|
|
// short lastCellNum = row.getLastCellNum();
|
|
|
|
|
for (int x=0;x<lastRowNum;x++){
|
|
|
|
|
Row row1 = sheet.getRow(x);
|
|
|
|
|
if (row1!=null){
|
|
|
|
|
//获取每一行的列数
|
|
|
|
|
short i = sheet.getRow(x).getLastCellNum();
|
|
|
|
|
if (row<i){
|
|
|
|
|
row=i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取表头行
|
|
|
|
|
Row headRow = sheet.getRow(rowStart);
|
|
|
|
|
if (headRow == null) {
|
|
|
|
@ -312,6 +329,9 @@ public class ExcelUtils {
|
|
|
|
|
}
|
|
|
|
|
int cellStart = headRow.getFirstCellNum();
|
|
|
|
|
int cellEnd = headRow.getLastCellNum();
|
|
|
|
|
if (cellEnd<row){
|
|
|
|
|
cellEnd = row;
|
|
|
|
|
}
|
|
|
|
|
LinkedHashMap<Integer, String> keyMap = new LinkedHashMap<>();
|
|
|
|
|
for (int j = cellStart; j < cellEnd; j++) {
|
|
|
|
|
// 获取表头数据
|
|
|
|
@ -319,11 +339,14 @@ public class ExcelUtils {
|
|
|
|
|
if (val != null && val.trim().length() != 0) {
|
|
|
|
|
keyMap.put(j, val);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
keyMap.put(j,"第"+(j+1)+"列");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果表头没有数据则不进行解析
|
|
|
|
|
if (keyMap.isEmpty()) {
|
|
|
|
|
return (JSONArray) Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
// if (keyMap.isEmpty()) {
|
|
|
|
|
// return (JSONArray) Collections.emptyList();
|
|
|
|
|
// }
|
|
|
|
|
// 获取每行JSON对象的值
|
|
|
|
|
JSONArray array = new JSONArray();
|
|
|
|
|
// 如果首行与尾行相同,表明只有一行,返回表头数据
|
|
|
|
|