| | |
| | | List<XWPFTableCell> cells = row.getTableCells(); |
| | | for (XWPFTableCell cell : cells) { |
| | | |
| | | |
| | | //如果当前表格包含%就代表需要替换 |
| | | if (checkText(cell.getText())) { |
| | | List<XWPFParagraph> paragraphs = cell.getParagraphs(); |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | |
| | | //获取所有行 |
| | | List<IRunElement> iRunElements = paragraph.getIRuns(); |
| | | List<XWPFRun> runs = new ArrayList<>(); |
| | | //遍历所有行 |
| | | for (IRunElement iRunElement : iRunElements) { |
| | | runs.add((XWPFRun) iRunElement); |
| | | } |
| | | int runPosition = 0; |
| | | //替换所有表格的文字 |
| | | for (XWPFRun run : runs) { |
| | | setTextValue(textMap, document, paragraph, runPosition, run); |
| | | } |
| | |
| | | |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName))); |
| | | |
| | | //设置文本 |
| | | changeText(document, textMap); |
| | | |
| | | //更改文本框 |
| | | if (Objects.equals(reportType, ReportTypeEnum.MAQV2.getCode())) { |
| | | changeTextBox(document, textMap); |
| | | } |
| | | |
| | | //插入表格 |
| | | addTableValue(document, autoTableMap); |
| | | |
| | | //更改表格的值 |
| | | changeTable(document, textMap); |
| | | |
| | | //设置图表控件 |
| | | changChar(textMap, document, reportType, templateType); |
| | | document.write(out); |
| | | } |
| | |
| | | document.write(out); |
| | | out.flush(); |
| | | } |
| | | |
| | | /** |
| | | * 设置图标控件 |
| | | * @param textMap |
| | | * @param document |
| | | * @param reportType |
| | | * @param templateType |
| | | */ |
| | | private static void changChar(Map<String, Object> textMap, XWPFDocument document, String reportType, String templateType) { |
| | | if (StringUtils.isEmpty(reportType) || StringUtils.isEmpty(templateType)) { |
| | | return; |
| | |
| | | if (ExamUtil.isListEmpty(charts)) { |
| | | return; |
| | | } |
| | | if (StringUtils.equals(reportType, "MAQ")) { |
| | | |
| | | if (StringUtils.equals(reportType, ReportTypeEnum.MAQ.getCode())) { |
| | | setMAQCompleteChars(textMap, charts); |
| | | } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQV2.getCode())) { |
| | | setMAQ_V2CompleteChars(textMap, charts); |
| | | } else if (StringUtils.equals(reportType, "RuiLin")) { |
| | | } else if (StringUtils.equals(reportType, ReportTypeEnum.RuiLin.getCode())) { |
| | | setRuiLinChar(textMap, charts); |
| | | } else { |
| | | return; |
| | | } |
| | | } |
| | | private static void setMAQ_V2CompleteChars(Map<String, Object> textMap, List<XWPFChart> charts) { |
| | | String p_People32 = textMap.get("P_Task31").toString(); |
| | | String p_Task31 = textMap.get("P_People32").toString(); |
| | | String p_Task31 = textMap.get("P_Task31").toString(); |
| | | String p_People32 = textMap.get("P_People32").toString(); |
| | | String P_INCON25 = textMap.get("P_INCON25").toString(); |
| | | String P_IM24 = textMap.get("P_IM24").toString(); |
| | | String P_SDE23 = textMap.get("P_SDE23").toString(); |
| | |
| | | List<CTBarSer> serList = ctBarChart.getSerList(); |
| | | CTBarSer ctBarSer = serList.get(0); |
| | | CTNumDataSource val = ctBarSer.getVal(); |
| | | val.getNumRef().getNumCache().getPtList().get(0).setV(p_Task31); |
| | | val.getNumRef().getNumCache().getPtList().get(1).setV(p_People32); |
| | | val.getNumRef().getNumCache().getPtList().get(0).setV(p_People32); |
| | | val.getNumRef().getNumCache().getPtList().get(1).setV(p_Task31); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |