|
@@ -22,10 +22,14 @@ public class ExcelToJson {
|
|
|
int xssfLastRowNum = xssfSheet.getLastRowNum();
|
|
|
JSONObject object = new JSONObject();
|
|
|
JSONObject second = new JSONObject();
|
|
|
+
|
|
|
+ boolean firstRow=true;
|
|
|
+
|
|
|
+ boolean changeFirstPage=false;
|
|
|
for(int rowNum = 1; rowNum <= xssfLastRowNum; rowNum++) {
|
|
|
XSSFRow xssfRow = xssfSheet.getRow(rowNum);
|
|
|
if(xssfRow == null) { continue; }
|
|
|
-
|
|
|
+
|
|
|
XSSFCell cell = xssfRow.getCell(0);
|
|
|
String cellValue0 = cell.getStringCellValue();
|
|
|
if(cellValue0 != "") {
|
|
@@ -35,16 +39,29 @@ public class ExcelToJson {
|
|
|
}
|
|
|
object.put("item", cellValue0);
|
|
|
object.put("children", new JSONArray());
|
|
|
+ changeFirstPage=true;
|
|
|
+ }else{
|
|
|
+ changeFirstPage=false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
cell = xssfRow.getCell(1);
|
|
|
String cellValue1 = cell.getStringCellValue();
|
|
|
if(cellValue1 != "") {
|
|
|
if(second.length() != 0) {
|
|
|
- JSONArray array = (JSONArray)object.get("children");
|
|
|
- array.put(second);
|
|
|
- object.put("children", array);
|
|
|
- second = new JSONObject();
|
|
|
+
|
|
|
+ if(changeFirstPage&&!firstRow){
|
|
|
+ JSONArray array = (JSONArray) dataArray.getJSONObject(dataArray.length()-1).get("children");
|
|
|
+ array.put(second);
|
|
|
+ second = new JSONObject();
|
|
|
+ changeFirstPage=false;
|
|
|
+ firstRow=false;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ JSONArray array = (JSONArray) object.get("children");
|
|
|
+ array.put(second);
|
|
|
+ object.put("children", array);
|
|
|
+ second = new JSONObject();
|
|
|
+ }
|
|
|
}
|
|
|
second.put("item", cellValue1);
|
|
|
second.put("children", new JSONArray());
|
|
@@ -56,10 +73,14 @@ public class ExcelToJson {
|
|
|
third.put("item", cell.getStringCellValue());
|
|
|
arr.put(third);
|
|
|
second.put("children", arr);
|
|
|
-
|
|
|
+ firstRow=false;
|
|
|
}
|
|
|
+
|
|
|
dataArray.put(object);
|
|
|
-
|
|
|
+
|
|
|
+ JSONArray array = (JSONArray) dataArray.getJSONObject(dataArray.length()-1).get("children");
|
|
|
+ array.put(second);
|
|
|
+
|
|
|
return dataArray;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|