| | |
| | | package com.example.springboot.service; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.ss.usermodel.CellValue; |
| | | import org.apache.poi.ss.usermodel.FormulaEvaluator; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | // 匹配玻璃 宽,高,线路 |
| | | public List<GlassInfo> NormalGlassInfo(double width, double height, String line) { |
| | | // |
| | | List<GlassInfo> Results=new ArrayList<GlassInfo>(); |
| | | List<GlassInfo> Results = new ArrayList<GlassInfo>(); |
| | | // 获取匹配设置 |
| | | MeasureSetting MeasureSetting = MeasureSettingMapper.SelectMeasureSetting(line); |
| | | if (height > 0 && width > 0 && MeasureSetting != null) { |
| | |
| | | } |
| | | return Results; |
| | | } |
| | | |
| | | //Execl表格 传入文件路径 |
| | | public List ReadExecl(String filename) { |
| | | try { |
| | | // 创建文件对象 |
| | | File file = new File(filename); |
| | | // 创建文件输入流对象 |
| | | FileInputStream inputStream = new FileInputStream(file); |
| | | // 创建工作簿对象 |
| | | Workbook workbook = WorkbookFactory.create(inputStream); |
| | | // 获取第一个工作表对象 |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | // 创建一个实体类集合,用于存储Excel数据 |
| | | |
| | | List Results=new ArrayList(); |
| | | int i=0; |
| | | // 遍历行 |
| | | for (Row row : sheet) { |
| | | // 遍历单元格 |
| | | List ResultRow=new ArrayList(); |
| | | //System.out.println(); |
| | | for (Cell cell : row) { |
| | | String LastCellvalue=""; |
| | | // 判断单元格类型是否为公式类型 |
| | | if (cell.getCellType() == CellType.FORMULA) { |
| | | // 使用公式计算器计算单元格的值 |
| | | FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); |
| | | CellValue cellValue = evaluator.evaluate(cell); |
| | | // 计算后的单元格值 |
| | | LastCellvalue=cellValue.getNumberValue()+""; |
| | | }else if(cell.getCellType() == CellType.NUMERIC){ |
| | | double value = cell.getNumericCellValue(); |
| | | if (value%1==0) { |
| | | LastCellvalue=Math.round(value)+""; |
| | | }else{ |
| | | LastCellvalue=value+""; |
| | | } |
| | | } else { |
| | | // 单元格值 |
| | | LastCellvalue=cell.toString(); |
| | | } |
| | | ResultRow.add(LastCellvalue); |
| | | //System.out.print(LastCellvalue+" "); |
| | | } |
| | | Results.add(ResultRow); |
| | | i++; |
| | | } |
| | | System.out.println(i); |
| | | // 关闭工作簿和输入流对象 |
| | | workbook.close(); |
| | | inputStream.close(); |
| | | return Results; |
| | | } catch (Exception e) { |
| | | // TODO: handle exception |
| | | System.out.println("异常"); |
| | | return new ArrayList(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |