| | |
| | | Exceldata exceldata = new Exceldata(); |
| | | Map<Integer, Object> project = new HashMap<>(); |
| | | HashMap<String, Object> datas1 = new HashMap<>(); |
| | | HashMap<String, Object> biaozhun = new HashMap<>(); |
| | | Boolean exitLoop = false; |
| | | for (int i = 0; i < workbook.getNumberOfSheets(); i++) { |
| | | String s = ""; |
| | |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } else { |
| | | } |
| | | else { |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | | if (cell.getColumnIndex() == 1) { |
| | | if (cell.getStringCellValue().equals("指标")) { |
| | | for (Cell cell1 : row) { |
| | | switch (cell1.getCellType()) { |
| | | case STRING: |
| | | biaozhun.put(project.get(cell1.getColumnIndex()).toString(), cell1.getStringCellValue()); |
| | | break; |
| | | case NUMERIC: |
| | | System.out.print(cell1.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell1.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | System.out.print(cell1.getCellFormula() + "\t"); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } |
| | | } |
| | | exitLoop = true; |
| | | break; |
| | | } |
| | | if (StringUtils.isNotEmpty(s)) { |
| | | datas.put(s, list); |
| | | String value = "zss"; |
| | | switch (row.getCell(1).getCellType()){ |
| | | case STRING: |
| | | value = cell.getStringCellValue(); |
| | | break; |
| | | } |
| | | list = new ArrayList<>(); |
| | | s = cell.getStringCellValue(); |
| | | datas.put(s, cell.getStringCellValue()); |
| | | System.out.print(cell.getStringCellValue() + "\t"); |
| | | if (value.equals("zss")){ |
| | | if (StringUtils.isNotEmpty(s)) { |
| | | datas.put(s, list); |
| | | } |
| | | list = new ArrayList<>(); |
| | | s = cell.getStringCellValue(); |
| | | datas.put(s, cell.getStringCellValue()); |
| | | System.out.print(cell.getStringCellValue() + "\t"); |
| | | } |
| | | break; |
| | | case NUMERIC: |
| | | int columnIndex = cell.getColumnIndex(); |
| | | Object o = project.get(columnIndex); |
| | | map.put(o.toString(), cell.getNumericCellValue()); |
| | | System.out.print(cell.getNumericCellValue() + "\t"); |
| | | int columnIndex = cell.getColumnIndex(); |
| | | Object o = project.get(columnIndex); |
| | | map.put(o.toString(), cell.getNumericCellValue()); |
| | | System.out.print(cell.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell.getBooleanCellValue() + "\t"); |
| | |
| | | } |
| | | } |
| | | } |
| | | list=list.stream().filter(map -> !map.isEmpty()).collect(Collectors.toList()); |
| | | datas.put(s, list); |
| | | map1.put(sheetName, datas); |
| | | datas1.putAll(map1); |
| | |
| | | } |
| | | } |
| | | System.out.println(map); |
| | | int size = map.size(); |
| | | for (String s1 : map.keySet()) { |
| | | String o = map.get(s1).toString(); |
| | | List<String> collect = Arrays.stream(o.split(",")).collect(Collectors.toList()); |
| | |
| | | } |
| | | } |
| | | System.out.println(map); |
| | | createWord(sonLaboratory, document, exceldata, map, insOrderFile); |
| | | createWord(sonLaboratory, document, exceldata, map, biaozhun, insOrderFile); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | |
| | | fileInputStream = new FileInputStream(new File(excelFilePath)); |
| | | workbook = new XSSFWorkbook(fileInputStream); // 对于 .xlsx 文件 |
| | | XWPFDocument document = new XWPFDocument(); |
| | | |
| | | Boolean exitLoop = false; |
| | | for (int i = 0; i < workbook.getNumberOfSheets(); i++) { |
| | | Exceldata exceldata = new Exceldata(); |
| | | HashMap<Integer, Object> project = new HashMap<>(); |
| | |
| | | Boolean biaoji = false; |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | for (Row row : sheet) { |
| | | |
| | | count++; |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | HashMap<String, Object> pingjun = new HashMap<>(); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | for (Cell cell : row) { |
| | | |
| | | if (row.getRowNum() == 0) { |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } else if (row.getRowNum() == 1) { |
| | | |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | | biaozhun.put(project.get(cell.getColumnIndex()).toString(), cell.getStringCellValue()); |
| | | break; |
| | | case NUMERIC: |
| | | System.out.print(cell.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | System.out.print(cell.getCellFormula() + "\t"); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } else if (row.getRowNum() > 2) { |
| | | |
| | | if (cell.getColumnIndex() == 0 && StringUtils.isNotEmpty(cell.getStringCellValue())) { |
| | | |
| | | if (map2.size() != 0) { |
| | | map2.put(port, list); |
| | | datas1.put(jiaodu, map2); |
| | |
| | | } |
| | | |
| | | } |
| | | } else if (value.equals("指标")) { |
| | | for (Cell cell1 : row) { |
| | | switch (cell1.getCellType()) { |
| | | case STRING: |
| | | biaozhun.put(project.get(cell1.getColumnIndex()).toString(), cell1.getStringCellValue()); |
| | | break; |
| | | case NUMERIC: |
| | | System.out.print(cell1.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell1.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | System.out.print(cell1.getCellFormula() + "\t"); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } |
| | | } else { |
| | | biaoji = true; |
| | | } |
| | |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | if (biaoji) { |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (map1.size() != 0) { |
| | | list.add(map1); |
| | | } |
| | |
| | | Map<String, List<HashMap<String, Object>>> numbers = (Map<String, List<HashMap<String, Object>>>) datas1.get(s); |
| | | for (String s1 : numbers.keySet()) { |
| | | List<HashMap<String, Object>> hashMaps = numbers.get(s1); |
| | | |
| | | List<Integer> floatList = new ArrayList<>(); |
| | | for (Map<String, Object> number : hashMaps) { |
| | | number.put("端口", s1); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | System.out.println(map); |
| | | |
| | | |
| | | int size = map.size(); |
| | | for (String s1 : map.keySet()) { |
| | | String o = map.get(s1).toString(); |
| | | |
| | | List<String> collect = Arrays.stream(o.split(",")).collect(Collectors.toList()); |
| | | int size1 = -1; |
| | | |
| | | for (String s : datas1.keySet()) { |
| | | Map<String, List<HashMap<String, Object>>> o1 = (Map<String, List<HashMap<String, Object>>>) datas1.get(s); |
| | | for (String s3 : o1.keySet()) { |
| | |
| | | String[] split = insOrderFile.getFileName().split("\\."); |
| | | String name = insOrderFile.getFileName().replace("#", "&").substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length())); |
| | | String url = UUID.randomUUID() + "_" + insSample.getSampleCode() + "_" + sonLaboratory + name + "解析的辐射站点报告.docx"; |
| | | url=url.replace("#", "&"); |
| | | url = url.replace("#", "&"); |
| | | FileOutputStream out = new FileOutputStream(wordUrl + "/" + url); |
| | | document.write(out); |
| | | out.close(); |
| | |
| | | } |
| | | |
| | | //近场 |
| | | public void createWord(String sonLaboratory, XWPFDocument document, Exceldata exceldata, HashMap<String, Object> map, InsOrderFile insOrderFile) throws IOException { |
| | | public void createWord(String sonLaboratory, XWPFDocument document, Exceldata exceldata, HashMap<String, Object> map, HashMap<String, Object> bz, InsOrderFile insOrderFile) throws IOException { |
| | | int size = 1; |
| | | XWPFParagraph paragraphs = document.createParagraph(); |
| | | XWPFRun runs = paragraphs.createRun(); |
| | |
| | | paragraph1.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run1 = paragraph1.createRun(); |
| | | run1.setText(s2); |
| | | // 调用方法提取第一个括号内的内容 |
| | | String firstContent = extractFirstContentFromBrackets(s2); |
| | | if (firstContent != null) { |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | paragraph2.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | run2.setText(firstContent); |
| | | // 单位 |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | if (s2.contains("增益")) { |
| | | run2.setText("dBi"); |
| | | } else if (s2.contains("波瓣宽度") || s2.contains("波束宽度") || s2.contains("下倾角")) { |
| | | run2.setText("°"); |
| | | } else if (s2.contains("前后比") || s2.contains("交叉极化") || s2.contains("旁瓣抑制") || s2.contains("下降") || s2.contains("零点填充") || s2.contains("副瓣电平")) { |
| | | run2.setText("dB"); |
| | | } else if (s2.contains("效率") || s2.contains("扇区占比")) { |
| | | run2.setText("%"); |
| | | } else { |
| | | System.out.println("没有找到括号内的内容。"); |
| | | run2.setText(""); |
| | | } |
| | | XWPFParagraph paragraph3 = table.getRow(0).getCell(3).getParagraphArray(0); |
| | | paragraph3.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run3 = paragraph3.createRun(); |
| | | run3.setText("/"); |
| | | if (bz.get(s2) != null) { |
| | | run3.setText(bz.get(s2).toString()); |
| | | } else run3.setText(""); |
| | | XWPFParagraph paragraph4 = table.getRow(0).getCell(4).getParagraphArray(0); |
| | | paragraph4.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run4 = paragraph4.createRun(); |
| | |
| | | List<String> collect = Arrays.stream(split).collect(Collectors.toList()); |
| | | collect.sort((o1, o21) -> Integer.parseInt(o1.substring((o1.length() - 1))) - Integer.parseInt(o21.substring(o21.length() - 1))); |
| | | |
| | | int size1 = 0; |
| | | |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | |
| | | |
| | |
| | | XWPFTable table = document.createTable(row, cell); |
| | | table.setWidth("100%"); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /* // 合并单元格 |
| | | mergeCellsHorizontally(table, 0, 0, 7);*/ |
| | | |
| | | |
| | | //垂直 |
| | | mergeCellsVertically(table, 0, 0, row - 1); |
| | | mergeCellsVertically(table, 1, 0, row - 1); |
| | |
| | | XWPFRun run1 = paragraph1.createRun(); |
| | | run1.setText(s2); |
| | | |
| | | // 调用方法提取第一个括号内的内容 |
| | | String firstContent = extractFirstContentFromBrackets(s2); |
| | | if (firstContent != null) { |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | run2.setText(firstContent); |
| | | // 单位 |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | if (s2.contains("增益")) { |
| | | run2.setText("dBi"); |
| | | } else if (s2.contains("波瓣宽度") || s2.contains("波束宽度") || s2.contains("下倾角")) { |
| | | run2.setText("°"); |
| | | } else if (s2.contains("前后比") || s2.contains("交叉极化") || s2.contains("旁瓣抑制") || s2.contains("下降") || s2.contains("零点填充") || s2.contains("副瓣电平")) { |
| | | run2.setText("dB"); |
| | | } else if (s2.contains("效率") || s2.contains("扇区占比")) { |
| | | run2.setText("%"); |
| | | } else { |
| | | System.out.println("没有找到括号内的内容。"); |
| | | run2.setText(""); |
| | | } |
| | | |
| | | |
| | | XWPFParagraph paragraph3 = table.getRow(0).getCell(3).getParagraphArray(0); |
| | | paragraph3.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run3 = paragraph3.createRun(); |
| | | if (bz.get(s2) != null) { |
| | | run3.setText(bz.get(s2).toString()); |
| | | } |
| | | } else run3.setText(""); |
| | | |
| | | |
| | | XWPFParagraph paragraph4 = table.getRow(0).getCell(4).getParagraphArray(0); |
| | |
| | | run4.setText("频率(MHz)"); |
| | | |
| | | XWPFParagraph paragraph5 = table.getRow(0).getCell(5).getParagraphArray(0); |
| | | paragraph5.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run5 = paragraph5.createRun(); |
| | | run5.setText("端口"); |
| | | |
| | |
| | | XWPFParagraph paragraph11 = table.getRow(row - 1).getCell(5).getParagraphArray(0); |
| | | XWPFRun run11 = paragraph11.createRun(); |
| | | double v = count / (Double.parseDouble(s1.toString()) * Double.parseDouble(i1.toString())); |
| | | run11.setText(o2.get(s2).toString()); |
| | | run11.setText(String.format("%.2f",(double)o2.get(s2))); |
| | | |
| | | size++; |
| | | } |
| | |
| | | table.getRow(i).getCell(col).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 提取第一个括号内的内容 |
| | | public static String extractFirstContentFromBrackets(String str) { |
| | | // 定义正则表达式,匹配括号内的内容,同时支持中文和英文括号 |
| | | Pattern pattern = Pattern.compile("\\((.*?)\\)|\\((.*?)\\)"); |
| | | Matcher matcher = pattern.matcher(str); |
| | | |
| | | // 查找第一个匹配的内容 |
| | | if (matcher.find()) { |
| | | // 获取括号内的内容,判断是中文括号还是英文括号 |
| | | return matcher.group(1) != null ? matcher.group(1) : matcher.group(2); |
| | | } |
| | | return null; // 如果没有找到匹配项,则返回null |
| | | } |
| | | |
| | | } |