gongdecai 3 年 前
コミット
3b57f46289

+ 69 - 55
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/controller/ImportController.java

@@ -36,73 +36,77 @@ import java.util.List;
  * @since 2021-08-30
  */
 @RestController
-@RequestMapping("/import")
+@RequestMapping("/importController")
 public class ImportController {
 
 //    private String filePath;
 //
-//    private List list = new ArrayList();
+    private List list = new ArrayList();
 //
 //
-//    public ImportController(String filePath) {
-//        this.filePath = filePath;
-//
+//    public String getFilePath() {
+//        return filePath;
 //    }
 //
+//    public void setFilePath(String filePath) {
+//        this.filePath = filePath;
+//    }
 //
-//    @GetMapping("/readDocument")
-//    public List<String> readDocument(String file) throws BiffException, IOException {
-//        ImportController excel = new ImportController(file);
-//
-//        excel.readExcel();
-//
-////        excel.outData();
+//    public List getList() {
 //        return list;
-//
 //    }
 //
-//    private void readExcel() throws IOException, BiffException {
-//        //创建输入流
-//
-//        InputStream stream = new FileInputStream(filePath);
-//
-//        //获取Excel文件对象
-//
-//        Workbook rwb = Workbook.getWorkbook(stream);
-//
-//        //获取文件的指定工作表 默认的第一个
-//
-//        Sheet sheet = rwb.getSheet(0);
-//
-//        //行数(表头的目录不需要,从1开始)
-//
-//        for (int i = 0; i < sheet.getRows(); i++) {
-//            //创建一个数组 用来存储每一列的值
-//
-//            String[] str = new String[sheet.getColumns()];
-//
-//            Cell cell = null;
-//
-//            //列数
-//
-//            for (int j = 0; j < sheet.getColumns(); j++) {
-//                //获取第i行,第j列的值
-//
-//                cell = sheet.getCell(j, i);
-//
-//                str[j] = cell.getContents();
-//
-//            }
-//
-//            //把刚获取的列存入list
-//
-//            list.add(str);
-//
-//        }
-//
+//    public void setList(List list) {
+//        this.list = list;
 //    }
 //
+//    public ImportController(String filePath) {
+//        this.filePath = filePath;
 //
+//    }
+
+    private void readExcel(String filePath) throws IOException, BiffException {
+        //创建输入流
+
+        InputStream stream = new FileInputStream(filePath);
+
+        //获取Excel文件对象
+
+        Workbook rwb = Workbook.getWorkbook(stream);
+
+        //获取文件的指定工作表 默认的第一个
+
+        Sheet sheet = rwb.getSheet(0);
+
+        //行数(表头的目录不需要,从1开始)
+//        List list = new ArrayList();
+        for (int i = 0; i < sheet.getRows(); i++) {
+            //创建一个数组 用来存储每一列的值
+
+            String[] str = new String[sheet.getColumns()];
+
+            Cell cell = null;
+
+            //列数
+
+            for (int j = 0; j < sheet.getColumns(); j++) {
+                //获取第i行,第j列的值
+
+                cell = sheet.getCell(j, i);
+
+                str[j] = cell.getContents();
+
+            }
+
+            //把刚获取的列存入list
+
+            list.add(str);
+
+        }
+
+    }
+
+
 //    private void outData() {
 //        for (int i = 0; i < list.size(); i++) {
 //            String[] str = (String[]) list.get(i);
@@ -117,8 +121,18 @@ public class ImportController {
 //        }
 //
 //    }
-//
-//
+
+    @GetMapping("/readDocument")
+    public List<String> readDocument(String file) throws Exception {
+//        ImportController excel = new ImportController(file);
+
+        this.readExcel(file);
+
+//        excel.outData();
+        return list;
+
+    }
+
 //
 //    @RequestMapping("toExcel")
 //
@@ -126,7 +140,7 @@ public class ImportController {
 //        return "admin/Excel";
 //
 //    }
-//
+
 
 }