| | |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | |
| | | lable.getAndIncrement(); |
| | | }); |
| | | }); |
| | | String url; |
| | | try { |
| | | ZipSecureFile.setMinInflateRatio(0.0001); |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/word1.docx"); |
| | | File file = File.createTempFile("temp", ".tmp"); |
| | | OutputStream outputStream = new FileOutputStream(file); |
| | | IOUtils.copy(inputStream, outputStream); |
| | | url = file.getAbsolutePath(); |
| | | } catch (FileNotFoundException e) { |
| | | throw new ErrorException("找不到模板文件"); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | ZipSecureFile.setMinInflateRatio(0.0001); |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/word1.docx"); |
| | | |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("title", title); |
| | | put("tables", tables); |
| | |
| | | FileInputStream stream = new FileInputStream(path); |
| | | XWPFDocument document = new XWPFDocument(stream); |
| | | List<XWPFTable> xwpfTables = document.getTables(); |
| | | for (int i = 1; i < xwpfTables.size(); i++) { |
| | | for (int i = 0; i < xwpfTables.size(); i++) { |
| | | Set<String> set1 = new HashSet<>(); |
| | | Map<String, Map<String, Integer>> maps = new HashMap<>(); |
| | | for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) { |
| | |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); |
| | | ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | List<RenderData> renderData = new ArrayList<>(); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | Style style = new Style(); |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | CTTcPr tcPr = cell.get(j).getCTTc().getTcPr(); |
| | | if (tcPr != null) { |
| | | //合并列 |
| | |
| | | text = row.get(index).getCell(j).getText(); |
| | | index--; |
| | | } |
| | | if (text.equals("合格")|| text.equals("不合格")){ |
| | | if (text.equals("合格") || text.equals("不合格")) { |
| | | textRenderData.setText(text + "∑25" + aa + j); |
| | | }else { |
| | | } else { |
| | | textRenderData.setText(text + "∑22" + aa + j); |
| | | } |
| | | } |
| | |
| | | tables4.add(table4); |
| | | } |
| | | } |
| | | |
| | | String url; |
| | | try { |
| | | ZipSecureFile.setMinInflateRatio(0.0001); |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); |
| | | File file = File.createTempFile("temp", ".tmp"); |
| | | OutputStream outputStream = new FileOutputStream(file); |
| | | IOUtils.copy(inputStream, outputStream); |
| | | url = file.getAbsolutePath(); |
| | | } catch (FileNotFoundException e) { |
| | | throw new ErrorException("找不到模板文件"); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | ZipSecureFile.setMinInflateRatio(0.0001); |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); |
| | | StringBuilder standardMethod2 = new StringBuilder(); |
| | | for (String s : standardMethod) { |
| | | standardMethod2.append(";\n").append(s); |
| | |
| | | List<Map<String, String>> finalDeviceList = deviceList; |
| | | List<Map<String, String>> sampleList = insSampleMapper.selectSampleList(orderId); |
| | | Integer userId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery() |
| | | .eq(InsSampleUser::getInsSampleId, orderId).last("limit 1")).getUserId(); |
| | | .eq(InsSampleUser::getInsSampleId, orderId) |
| | | .eq(InsSampleUser::getState,0) |
| | | .last("limit 1")).getUserId(); |
| | | String signatureUrl; |
| | | try { |
| | | signatureUrl = userMapper.selectById(userId).getSignatureUrl(); |
| | |
| | | title3 = "辐射方向图参数"; |
| | | } |
| | | String finalTitle = title3; |
| | | XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("order", insOrder); |
| | | put("report", insReport); |
| | |
| | | for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) { |
| | | if (v.get("ec") > v.get("sc")) { |
| | | try { |
| | | TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec")); |
| | | mergeCellsHorizontally(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec")); |
| | | // TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec")); |
| | | } catch (Exception e) { |
| | | System.out.println("合并出错"); |
| | | } |
| | | } |
| | | } |
| | | if (v.get("er") > v.get("sr")) { |
| | | try { |
| | | TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er")); |
| | | mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er")); |
| | | // TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er")); |
| | | } catch (Exception e) { |
| | | System.out.println("合并出错"); |
| | | } |
| | | } |
| | | } |
| | |
| | | }); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // 水平合并单元格 |
| | | private static void mergeCellsHorizontally(XWPFTable table, int row, int fromCol, int toCol) { |
| | | for (int i = fromCol; i <= toCol; i++) { |
| | | if (i == fromCol) { |
| | | table.getRow(row).getCell(i).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); |
| | | } else { |
| | | table.getRow(row).getCell(i).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 垂直合并单元格 |
| | | private static void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) { |
| | | for (int i = fromRow; i <= toRow; i++) { |
| | | if (i == fromRow) { |
| | | table.getRow(i).getCell(col).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); |
| | | } else { |
| | | table.getRow(i).getCell(col).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); |
| | | } |
| | | } |
| | | } |
| | | } |