| | |
| | | } |
| | | |
| | | public static List<double[][]> readMethodExcel(MultipartFile file) throws IOException { |
| | | Workbook workbook = WorkbookFactory.create(file.getInputStream()); |
| | | //获取工作薄里面sheet的个数 |
| | | int sheetNum = workbook.getNumberOfSheets(); |
| | | List<double[][]> datas = new ArrayList<>(sheetNum - 1); |
| | | //从第二个sheet开始读,第一个为示例 |
| | | for (int i = 1; i < sheetNum; i++) { |
| | | Sheet sheet = workbook.getSheetAt(i); |
| | | //获取sheet中有数据的行数 |
| | | int rows = sheet.getPhysicalNumberOfRows(); |
| | | double[][] doubles2 = new double[rows][]; |
| | | for (int j = 0; j < rows; j++) { |
| | | //获取每一行的数据 |
| | | Row row = sheet.getRow(j); |
| | | //得到每一行中有效单元格的数据 |
| | | short cells = row.getLastCellNum(); |
| | | //定义一个doubles数组用来存储读取单元格的数据 |
| | | double[] doubles1 = new double[cells]; |
| | | //遍历每一个有效的单元格数据 |
| | | for (int k = 0; k < cells; k++) { |
| | | //获取每一个单元格的数据 |
| | | Cell cell = row.getCell(k, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); |
| | | doubles1[k] = cell.getNumericCellValue(); |
| | | List<double[][]> datas; |
| | | try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { |
| | | //获取工作薄里面sheet的个数 |
| | | int sheetNum = workbook.getNumberOfSheets(); |
| | | datas = new ArrayList<>(sheetNum - 1); |
| | | //从第二个sheet开始读,第一个为示例 |
| | | for (int i = 1; i < sheetNum; i++) { |
| | | Sheet sheet = workbook.getSheetAt(i); |
| | | //获取sheet中有数据的行数 |
| | | int rows = sheet.getPhysicalNumberOfRows(); |
| | | double[][] doubles2 = new double[rows][]; |
| | | for (int j = 0; j < rows; j++) { |
| | | //获取每一行的数据 |
| | | Row row = sheet.getRow(j); |
| | | //得到每一行中有效单元格的数据 |
| | | short cells = row.getLastCellNum(); |
| | | //定义一个doubles数组用来存储读取单元格的数据 |
| | | double[] doubles1 = new double[cells]; |
| | | //遍历每一个有效的单元格数据 |
| | | for (int k = 0; k < cells; k++) { |
| | | //获取每一个单元格的数据 |
| | | Cell cell = row.getCell(k, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); |
| | | doubles1[k] = cell.getNumericCellValue(); |
| | | } |
| | | doubles2[j] = doubles1; |
| | | } |
| | | doubles2[j] = doubles1; |
| | | datas.add(doubles2); |
| | | } |
| | | datas.add(doubles2); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("解析Excel异常",e); |
| | | } |
| | | |
| | | return datas; |