|
@@ -0,0 +1,44 @@
|
|
|
|
+package com.persagy.ibms.data.sdk.util;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+public class ExeclReadEquipStaticInfoUtil {
|
|
|
|
+
|
|
|
|
+ public static JSONObject ReadEquipStaticInfo(String firstName, String sheetName) throws Exception {
|
|
|
|
+ String filepath=Constant.GetPath() + Constant.getSeperator() + firstName+".xlsx";
|
|
|
|
+ Workbook workbook = WorkbookFactory.create(new File(filepath));
|
|
|
|
+ Sheet sheet = workbook.getSheet(sheetName);
|
|
|
|
+ JSONObject object=new JSONObject(new LinkedHashMap());
|
|
|
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
|
+ //获取合并单元格的值
|
|
|
|
+ CellRangeAddress ca = sheet.getMergedRegion(i);
|
|
|
|
+ int firstRow = ca.getFirstRow();
|
|
|
|
+ Row fRow = sheet.getRow(firstRow);
|
|
|
|
+ Cell fCell = fRow.getCell(0);
|
|
|
|
+ String caVal= getCellValue(fCell) ;
|
|
|
|
+ //获取合并单元格之后的值,形成树形结构
|
|
|
|
+ List dic = new JSONArray();
|
|
|
|
+ for (int j=firstRow;j<= ca.getLastRow();j++)
|
|
|
|
+ {
|
|
|
|
+ Row row=sheet.getRow(j);
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
|
+ obj.put("name", getCellValue(row.getCell(1)));
|
|
|
|
+ obj.put("code", getCellValue(row.getCell(2)));
|
|
|
|
+ obj.put("enable", row.getCell(3).getBooleanCellValue());
|
|
|
|
+ dic.add(obj);
|
|
|
|
+ }
|
|
|
|
+ object.put(caVal,dic);
|
|
|
|
+ }
|
|
|
|
+ return object;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String getCellValue(Cell cell){
|
|
|
|
+ if(cell == null) return "";
|
|
|
|
+ return cell.getStringCellValue();
|
|
|
|
+ }
|
|
|
|
+}
|