| | |
| | | import com.ots.project.tool.exam.ExamUtil; |
| | | import com.ots.project.tool.exam.ImageUtil; |
| | | import com.ots.project.tool.exam.ZipUtil; |
| | | import com.ots.project.tool.report.MAQTR.chart.MAQTRChart; |
| | | import com.ots.project.tool.report.PAQ.chart.PAQChart; |
| | | import org.apache.commons.collections.map.HashedMap; |
| | | import org.apache.poi.ooxml.POIXMLDocument; |
| | |
| | | put("<FontSize_11>", "</FontSize_11>"); |
| | | }}; |
| | | public static final int DEFAULT_FONT_SIZE = 10; |
| | | |
| | | |
| | | public static boolean changWord(String inputUrl, String outputUrl, |
| | | Map<String, Object> textMap, Map<String, Object> tableMap) { |
| | | |
| | | |
| | | try { |
| | | |
| | | |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl)); |
| | | |
| | | |
| | | WordUtil.changeText(document, textMap); |
| | | |
| | | |
| | | WordUtil.changeTable(document, textMap); |
| | | |
| | | |
| | | File file = new File(outputUrl); |
| | | FileOutputStream stream = new FileOutputStream(file); |
| | | document.write(stream); |
| | |
| | | } |
| | | public static OutputStream getReportWord(String inputUrl, String outputUrl, |
| | | Map<String, Object> textMap, Map<String, Object> tableMap) { |
| | | |
| | | |
| | | try { |
| | | |
| | | |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl)); |
| | | |
| | | |
| | | WordUtil.changeText(document, textMap); |
| | | |
| | | |
| | | WordUtil.changeTable(document, textMap); |
| | | |
| | | |
| | | File file = new File(outputUrl); |
| | | return new FileOutputStream(file); |
| | | } catch (IOException e) { |
| | |
| | | } |
| | | public static boolean changWord(String inputUrl, String outputUrl, |
| | | Map<String, Object> textMap, WordParam wordParam) { |
| | | |
| | | |
| | | boolean changeFlag = true; |
| | | try { |
| | | |
| | | |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl)); |
| | | |
| | | |
| | | WordUtil.changeText(document, textMap); |
| | | |
| | | |
| | | File file = new File(outputUrl); |
| | | FileOutputStream stream = new FileOutputStream(file); |
| | | document.write(stream); |
| | |
| | | } |
| | | return changeFlag; |
| | | } |
| | | |
| | | |
| | | public static void changeText(XWPFDocument document, Map<String, Object> textMap) throws IOException, InvalidFormatException { |
| | | |
| | | |
| | | setHeader(document, textMap); |
| | | |
| | | |
| | | |
| | | |
| | | List<IBodyElement> elements = document.getBodyElements(); |
| | | List<XWPFParagraph> paragraphs = new ArrayList<>(); |
| | | for (IBodyElement iBodyElement : elements) { |
| | |
| | | } |
| | | } |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | |
| | | |
| | | String text = paragraph.getText(); |
| | | if (checkText(text)) { |
| | | |
| | | |
| | | List<IRunElement> iRunElements = paragraph.getIRuns(); |
| | | List<XWPFRun> runs = new ArrayList<>(); |
| | | for (IRunElement iRunElement : iRunElements) { |
| | |
| | | } |
| | | int runPosition = 0; |
| | | for (XWPFRun run : runs) { |
| | | |
| | | |
| | | String changeValueStr = changeValue(run.toString(), textMap, run, paragraph, document, runPosition); |
| | | if (!StringUtils.equals(changeValueStr, "NoChangValue")) { |
| | | run.setText(changeValueStr, 0); |
| | | } |
| | | runPosition++; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private static void setHeader(XWPFDocument document, Map<String, Object> textMap) { |
| | | try { |
| | | List<XWPFHeader> headerList = document.getHeaderList(); |
| | |
| | | setTableValue(document, textMap, tables); |
| | | } |
| | | public static void changePage(XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException { |
| | | |
| | | |
| | | List<XWPFParagraph> paragraphs = document.getParagraphs(); |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | |
| | | |
| | | String text = paragraph.getText(); |
| | | if (text.indexOf("%page-change%") != -1) { |
| | | List<XWPFRun> runs = paragraph.getRuns(); |
| | | for (XWPFRun run : runs) { |
| | | |
| | | |
| | | if (StringUtils.equals(run.toString(), "%page-change%")) { |
| | | run.setText("", 0); |
| | | } |
| | |
| | | } |
| | | } |
| | | public static void changeLine(XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException { |
| | | |
| | | |
| | | List<XWPFParagraph> paragraphs = document.getParagraphs(); |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | |
| | | |
| | | String text = paragraph.getText(); |
| | | if (text.indexOf("%line-feed%") != -1) { |
| | | List<XWPFRun> runs = paragraph.getRuns(); |
| | | for (XWPFRun run : runs) { |
| | | |
| | | |
| | | if (StringUtils.equals(run.toString(), "%line-feed%")) { |
| | | run.setText("", 0); |
| | | run.addBreak(); |
| | |
| | | } |
| | | private static void setPicture(XWPFRun run, WordParam wordParam) throws org.apache.poi.openxml4j.exceptions.InvalidFormatException, IOException { |
| | | InputStream in = new FileInputStream(wordParam.getContent()); |
| | | |
| | | |
| | | BufferedImage bufferedImage = ImageUtil.getImage(wordParam.getContent()); |
| | | int width = (int) Math.round(bufferedImage.getWidth()); |
| | | int height = (int) Math.round(bufferedImage.getHeight()); |
| | |
| | | run.addPicture(in, Document.PICTURE_TYPE_PNG, "TEST", width * emuSelf, height * emuSelf); |
| | | in.close(); |
| | | if (wordParam.isMove()) { |
| | | |
| | | |
| | | CTDrawing drawing = run.getCTR().getDrawingArray(0); |
| | | CTGraphicalObject graphicalobject = drawing.getInlineArray(0).getGraphic(); |
| | | |
| | | |
| | | CTAnchor anchor = getAnchorWithGraphic(graphicalobject, "TEST1", |
| | | Units.toEMU(wordParam.getPicWidth()), Units.toEMU(wordParam.getPicHeight()), |
| | | Units.toEMU(wordParam.getX()), Units.toEMU(wordParam.getY()), false, wordParam.getTopPosition()); |
| | |
| | | drawing.removeInline(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | public static CTAnchor getAnchorWithGraphic(CTGraphicalObject ctGraphicalObject, |
| | | String deskFileName, int width, int height, |
| | | int leftOffset, int topOffset, boolean behind, int topPosition) { |
| | |
| | | anchor.setGraphic(ctGraphicalObject); |
| | | return anchor; |
| | | } |
| | | |
| | | |
| | | public static void changeTable(XWPFDocument document, Map<String, Object> textMap) { |
| | | |
| | | |
| | | List<XWPFTable> tables = document.getTables(); |
| | | setTableValue(document, textMap, tables); |
| | | } |
| | |
| | | */ |
| | | private static void setTableValue(XWPFDocument document, Map<String, Object> textMap, List<XWPFTable> tables) { |
| | | for (int i = 0; i < tables.size(); i++) { |
| | | |
| | | |
| | | log.info("第" + (i + 1) + "个表:"); |
| | | try { |
| | | XWPFTable table = tables.get(i); |
| | |
| | | log.info("表行数:{}",table.getRows().size()); |
| | | log.info("表格数据:" + table.getText()); |
| | | //增加表格或者減少表格 |
| | | addOrDelTableRow(table,i,textMap); |
| | | if (Objects.equals(textMap.get("sendEmailFileName"), ReportTypeEnum.JAQ.getCode())) { |
| | | addOrDelTableRow(table,i,textMap); |
| | | } |
| | | if (checkText(table.getText())) { |
| | | List<XWPFTableRow> rows = table.getRows(); |
| | | |
| | | |
| | | eachTable(rows, textMap, document); |
| | | } |
| | | } |
| | |
| | | } |
| | | List<XWPFTable> tables = document.getTables(); |
| | | for (int i = 0; i < tables.size(); i++) { |
| | | |
| | | |
| | | log.info("第" + (i + 1) + "个表:"); |
| | | try { |
| | | XWPFTable table = tables.get(i); |
| | | if (table.getRows().size() > 0) { |
| | | |
| | | |
| | | log.info("添加行表格数据:" + table.getText()); |
| | | |
| | | |
| | | Map<Integer, List<String[]>> mapRowsMap = autoTableMap.get(i); |
| | | log.info("插入" + table.getText()); |
| | | insertTable(table, mapRowsMap.get(i), 1); |
| | |
| | | } |
| | | mapRowsMap.put(3, table4List); |
| | | }*/ |
| | | |
| | | |
| | | public static void eachTable(List<XWPFTableRow> rows, Map<String, Object> textMap, XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException { |
| | | for (XWPFTableRow row : rows) { |
| | | List<XWPFTableCell> cells = row.getTableCells(); |
| | | for (XWPFTableCell cell : cells) { |
| | | |
| | | |
| | | //如果当前表格包含%就代表需要替换 |
| | | if (checkText(cell.getText())) { |
| | | List<XWPFParagraph> paragraphs = cell.getParagraphs(); |
| | |
| | | try { |
| | | run.setText(changeValue(run.toString(), textMap, run, paragraph, document, runPosition), 0); |
| | | } catch (Exception e) { |
| | | |
| | | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void insertTable(XWPFTable table, List<String[]> tableList, int inserRowNum) { |
| | | |
| | | |
| | | for (int i = 0; i < tableList.size(); i++) { |
| | | XWPFTableRow row = table.createRow(); |
| | | } |
| | | |
| | | |
| | | XWPFTableRow headXwpfTableRow = table.getRows().get(0); |
| | | for (int i = inserRowNum; i <= tableList.size(); i++) { |
| | | XWPFTableRow newRow = table.getRow(i); |
| | |
| | | try { |
| | | XWPFTableCell cell = cells.get(j); |
| | | cell.setText(tableList.get(i - 1)[j]); |
| | | |
| | | |
| | | cell.getParagraphs().get(0).getCTP().setPPr(headXwpfTableRow.getCell(0).getParagraphs().get(0).getCTP().getPPr()); |
| | | } catch (Exception e) { |
| | | } |
| | |
| | | int count = oldLength - newLength; |
| | | return count; |
| | | } |
| | | |
| | | |
| | | public static String changeValue(String runValue, Map<String, Object> textMap, XWPFRun run, XWPFParagraph paragraph, XWPFDocument document, int runPosition) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException { |
| | | log.debug("changeText:{}",runValue); |
| | | Set<Map.Entry<String, Object>> textSets = textMap.entrySet(); |
| | | for (Map.Entry<String, Object> textSet : textSets) { |
| | | |
| | | |
| | | String key = "%" + textSet.getKey() + "%"; |
| | | if (runValue.indexOf("%page-change%") != -1) { |
| | | runValue = ""; |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | if (checkText(runValue)) { |
| | | runValue = runValue.replaceAll("%.*%", ""); |
| | | runValue = runValue.replaceAll("N/A NONE", ""); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | return runValue; |
| | | } |
| | | private static String setOtherStyle(String runValue, XWPFParagraph paragraph, int runPosition, XWPFRun oldRun) { |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | int position = 0; |
| | | int pointer = 0; |
| | | int end = runValue.length(); |
| | |
| | | if (StringUtils.isNotEmpty(newRunStr)) { |
| | | newRunStr = newRunStr.replaceAll("<BoldText>", ""); |
| | | newRunStr = newRunStr.replaceAll("</BoldText>", ""); |
| | | |
| | | |
| | | String rgbStr = getRGBStr(newRunStr, oldRun); |
| | | if (rgbStr == null) { |
| | | rgbStr = oldRun.getColor(); |
| | | } |
| | | |
| | | |
| | | int fontSize = getFontSize(newRunStr, oldRun); |
| | | if (fontSize == -1) { |
| | | fontSize = oldRun.getFontSize(); |
| | |
| | | pointer = end; |
| | | } |
| | | } |
| | | |
| | | |
| | | paragraph.removeRun(runPosition); |
| | | return "NoChangValue"; |
| | | } |
| | |
| | | |
| | | |
| | | private static void changOtherPicture(XWPFParagraph paragraph) { |
| | | |
| | | |
| | | String paragraphText = paragraph.getText(); |
| | | if (paragraphText.indexOf("{start.png}") == -1) { |
| | | return; |
| | |
| | | position = paragraphText.indexOf("{start.png}", position); |
| | | String value = ""; |
| | | if (position == -1) { |
| | | |
| | | |
| | | runPosition = insertPicRun(paragraph, oldRun, runPosition, paragraphText.substring(poiter, end)); |
| | | break; |
| | | } |
| | | if (poiter == position) { |
| | | position = position + starLength; |
| | | |
| | | |
| | | runPosition = insertSmallRunPic(paragraph, runPosition); |
| | | poiter = position; |
| | | continue; |
| | | } else { |
| | | |
| | | |
| | | runPosition = insertPicRun(paragraph, oldRun, runPosition, paragraphText.substring(poiter, position)); |
| | | poiter = position; |
| | | position = poiter + starLength; |
| | | |
| | | |
| | | runPosition = insertSmallRunPic(paragraph, runPosition); |
| | | poiter = position; |
| | | } |
| | |
| | | insertRun.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize); |
| | | return runPosition; |
| | | } |
| | | |
| | | |
| | | private static String changeWordAndPicValue(String runValue, XWPFRun run, Map.Entry<String, Object> textSet, String key, XWPFParagraph paragraph, XWPFDocument document) throws org.apache.poi.openxml4j.exceptions.InvalidFormatException, IOException { |
| | | if (textSet.getValue() instanceof WordParam) { |
| | | setPicture(run, (WordParam) textSet.getValue()); |
| | | } else { |
| | | String keyTemp = textSet.getKey(); |
| | | String keyValue = Objects.isNull(textSet.getValue()) ? "" : textSet.getValue().toString(); |
| | | if (StringUtils.contains(keyValue, "%line-feed%")) { |
| | | |
| | | String[] keyValues = keyValue.split("%line-feed%"); |
| | | runValue = delDynList(keyTemp, Arrays.asList(keyValues), paragraph, document); |
| | | if (StringUtils.contains(keyValue, "%line-feed%") || StringUtils.contains(keyValue, "%table-line-feed%")) { |
| | | |
| | | //表格里的换行 特殊处理 因为没有段落 |
| | | if(StringUtils.contains(keyValue, "table")){ |
| | | String[] keyValues = keyValue.split("%table-line-feed%"); |
| | | runValue = delDynList(keyTemp, Arrays.asList(keyValues), paragraph, document,1); |
| | | }else{ |
| | | String[] keyValues = keyValue.split("%line-feed%"); |
| | | runValue = delDynList(keyTemp, Arrays.asList(keyValues), paragraph, document,0); |
| | | } |
| | | } |
| | | log.info("ChangeValue的key值:" + key + " ChangeValue的value值:" + keyValue); |
| | | runValue = runValue.replaceAll(key, keyValue); |
| | | } |
| | | return runValue; |
| | | } |
| | | |
| | | |
| | | public AjaxResult exportBaseOrDetailReport(String fileName, List<String> deleteFileStrList, List<String> fileNameList) { |
| | | |
| | | |
| | | try { |
| | | zipWord(fileName, fileNameList); |
| | | } catch (FileNotFoundException e) { |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | deleteFileByStr(deleteFileStrList); |
| | | return AjaxResult.success(fileName + ".zip"); |
| | | } |
| | | public AjaxResult exportZipKeepFiles(String fileName, List<String> deleteFileStrList, List<String> fileNameList) throws FileNotFoundException { |
| | | |
| | | |
| | | zipKeepWord(fileName, fileNameList); |
| | | |
| | | |
| | | deleteFileByStr(deleteFileStrList); |
| | | return AjaxResult.success(fileName + ".zip"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public static String makeReportFile(String fileName, TReportTemplate tReportTemplate, Map<String, Object> textMap, Map<Integer, Map<Integer, List<String[]>>> autoTableMap, List<String> deleteFileStrList) { |
| | | String returnMessage = "导出模板转移错误:"; |
| | | InputStream in = null; |
| | |
| | | String zipFilePath = ""; |
| | | String reportName = ""; |
| | | try { |
| | | |
| | | |
| | | String reportType = tReportTemplate.getReportType(); |
| | | reportType = getTypeIfIsSAQ(tReportTemplate, reportType); |
| | | reportType = getPositionIfJAQ(textMap, reportType); |
| | | reportName = textMap.get("sendEmailFileName") + "_" + reportType + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getTemplateType()).getCode() + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getLangType()).getCode() + ".docx"; |
| | | |
| | | |
| | | reportName = reportName.replaceAll(" ", "_"); |
| | | out = getDownLoadFileOutputStream(reportName); |
| | | |
| | | |
| | | log.info("reportTemplate:" + fileName); |
| | | String templateType = tReportTemplate.getTemplateType(); |
| | | setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), templateType, autoTableMap); |
| | | //String templateType = tReportTemplate.getTemplateType(); |
| | | setChageWord(fileName, out, textMap, tReportTemplate.getReportType(),tReportTemplate.getDataPath(), autoTableMap); |
| | | out.flush(); |
| | | changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType()); |
| | | //PAQ采用新的doc转pdf |
| | | if(!ReportTypeEnum.PAQ.getCode().equals(reportType)){ |
| | | ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/"); |
| | | }else{ |
| | | //PAQ、MAQTR采用新的doc转pdf |
| | | if(ReportTypeEnum.PAQ.getCode().equals(reportType) || ReportTypeEnum.MAQTR.getCode().equals(reportType)){ |
| | | PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName); |
| | | }else{ |
| | | ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/"); |
| | | |
| | | } |
| | | zipFilePath = getPdfPath(reportName); |
| | | |
| | | |
| | | deleteFileStrList.add(EssConfig.getProfile() + "/" + reportName); |
| | | } catch (Exception ex) { |
| | | returnMessage = returnMessage + ex.getMessage(); |
| | |
| | | return reportName.substring(0, reportName.lastIndexOf(".")) + ".pdf"; |
| | | } |
| | | public static void deleteFileByStr(List<String> deleteFileStrList) { |
| | | |
| | | |
| | | for (String deleteStr : deleteFileStrList) { |
| | | File file = new File(deleteStr); |
| | | file.delete(); |
| | |
| | | } |
| | | ZipUtil.toZip(fileList, zipOut); |
| | | } |
| | | |
| | | |
| | | private static FileOutputStream getDownLoadFileOutputStream(String fileName) throws FileNotFoundException { |
| | | File outFile = new File(EssConfig.getProfile() + "/" + fileName); |
| | | if (!outFile.getParentFile().exists()) { |
| | |
| | | } |
| | | return new FileOutputStream(outFile); |
| | | } |
| | | private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType, String templateType, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException, DocumentException { |
| | | String filePath = getTemplateDownLoadPathByUpLoad(fileName); |
| | | |
| | | |
| | | /** |
| | | * 内容变更 |
| | | * @param fileName |
| | | * @param out |
| | | * @param textMap |
| | | * @param reportType |
| | | * @param autoTableMap |
| | | * @throws IOException |
| | | * @throws InvalidFormatException |
| | | * @throws DocumentException |
| | | */ |
| | | private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType,String dataPath, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, InvalidFormatException, DocumentException { |
| | | //String filePath = getTemplateDownLoadPathByUpLoad(fileName); |
| | | |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName))); |
| | | |
| | | //设置文本 |
| | |
| | | //设置文本框 |
| | | changeTextBox(document, textMap); |
| | | |
| | | //设置图表 |
| | | if (Objects.equals(reportType, ReportTypeEnum.PAQ.getCode())) { |
| | | PAQChart.changeChart(document, textMap); |
| | | } |
| | | |
| | | //插入表格 |
| | | addTableValue(document, autoTableMap); |
| | | |
| | |
| | | changeTable(document, textMap); |
| | | |
| | | //设置图表控件 |
| | | changChar(textMap, document, reportType, templateType); |
| | | changChart(textMap, document, reportType,dataPath); |
| | | document.write(out); |
| | | } |
| | | private static void changeTextBox(XWPFDocument document, Map<String, Object> textMap) throws DocumentException { |
| | | List<XWPFParagraph> paragraphs = document.getParagraphs(); |
| | | |
| | | |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | CTR[] rArray = paragraph.getCTP().getRArray(); |
| | | for (XmlObject ctr : rArray) { |
| | |
| | | String repText = ""; |
| | | Set<Map.Entry<String, Object>> textSets = textMap.entrySet(); |
| | | for (Map.Entry<String, Object> textSet : textSets) { |
| | | |
| | | |
| | | String key = "%" + textSet.getKey() + "%"; |
| | | if (text.indexOf(key) != -1) { |
| | | text = text.replaceAll(key, (String) textMap.get(textSet.getKey())); |
| | |
| | | if (StringUtils.isEmpty(fileName) || CollUtil.isEmpty(jaqTableStyleList)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(EssConfig.getProfile() + "/" + fileName)); |
| | | if (Objects.isNull(document)) { |
| | | return; |
| | |
| | | |
| | | /** |
| | | * 设置图标控件 |
| | | * @param textMap |
| | | * @param document |
| | | * @param reportType |
| | | * @param templateType |
| | | * @param textMap 替换text |
| | | * @param document 报告文件 |
| | | * @param reportType 报告类型 |
| | | * @param dataPath MAQTR数据路径 |
| | | */ |
| | | private static void changChar(Map<String, Object> textMap, XWPFDocument document, String reportType, String templateType) { |
| | | if (StringUtils.isEmpty(reportType) || StringUtils.isEmpty(templateType)) { |
| | | private static void changChart(Map<String, Object> textMap, XWPFDocument document, String reportType,String dataPath) { |
| | | if (StringUtils.isEmpty(reportType)) { |
| | | return; |
| | | } |
| | | List<XWPFChart> charts = document.getCharts(); |
| | |
| | | setMAQ_V2CompleteChars(textMap, charts); |
| | | } else if (StringUtils.equals(reportType, ReportTypeEnum.RuiLin.getCode())) { |
| | | setRuiLinChar(textMap, charts); |
| | | } else if (StringUtils.equals(reportType, ReportTypeEnum.PAQ.getCode())) { |
| | | PAQChart.changeChart(document, textMap); |
| | | } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQTR.getCode())) { |
| | | MAQTRChart.changeMAQTRChart(document, dataPath); |
| | | } else { |
| | | return; |
| | | } |
| | |
| | | String P_INCON25 = textMap.get("P_INCON25").toString(); |
| | | String P_IM24 = textMap.get("P_IM24").toString(); |
| | | String P_SDE23 = textMap.get("P_SDE23").toString(); |
| | | |
| | | |
| | | for (XWPFChart xwpfChart : charts) { |
| | | try { |
| | | CTChart ctChart = xwpfChart.getCTChart(); |
| | |
| | | setCharMap.put(12, WordUtil::set12RuilinChartList); |
| | | setCharMap.put(38, WordUtil::set38RuilinChartList); |
| | | setCharMap.put(4, WordUtil::set4RuilinChartList); |
| | | |
| | | |
| | | XWPFChart xwpfChart0 = charts.get(0); |
| | | List<CTNumVal> ptList = xwpfChart0.getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList(); |
| | | setCharMap.get(char0Size).setsetRuilinChartList(textMap, ptList); |
| | | |
| | | |
| | | XWPFChart xwpfChart1 = charts.get(1); |
| | | ptList = xwpfChart1.getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList(); |
| | | setCharMap.get(char1Size).setsetRuilinChartList(textMap, ptList); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | private static void setMAQCompleteChars(Map<String, Object> textMap, List<XWPFChart> charts) { |
| | | String p_Task31 = textMap.get("P_Task31").toString(); |
| | | String p_People32 = textMap.get("P_People32").toString(); |
| | | |
| | | |
| | | XWPFChart xwpfChart = charts.get(0); |
| | | if (!setMAQbarGraph(p_Task31, p_People32, xwpfChart)) { |
| | | log.info("第二个是条形"); |
| | | setMAQcanvasChart(p_Task31, p_People32, xwpfChart); |
| | | } |
| | | |
| | | |
| | | XWPFChart xwpfChartLeadershipFourSided = charts.get(1); |
| | | if (!setMAQcanvasChart(p_Task31, p_People32, xwpfChartLeadershipFourSided)) { |
| | | log.info("第一个是画布"); |
| | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | private String getTemplateDownLoadPath(String fileName) { |
| | | |
| | | |
| | | return EssConfig.getReportTemplates() + fileName; |
| | | } |
| | | |
| | | |
| | | private static String getTemplateDownLoadPathByUpLoad(String fileName) { |
| | | return EssConfig.getUploadPath() + fileName; |
| | | } |
| | | |
| | | |
| | | public static String getTemplatePicture(String pictureName) { |
| | | |
| | | |
| | | return EssConfig.getReportTemplates() + pictureName; |
| | | } |
| | | private static void closeChannel(InputStream inputStream) { |
| | |
| | | } |
| | | } |
| | | public File getAbsoluteFileZipByName(String filename) { |
| | | String downloadPath = EssConfig.getDownloadPath() + filename; |
| | | String downloadPath = EssConfig.getDownloadPath() + "/" + filename; |
| | | File desc = new File(downloadPath); |
| | | if (!desc.getParentFile().exists()) { |
| | | desc.getParentFile().mkdirs(); |
| | | } |
| | | return desc; |
| | | } |
| | | |
| | | |
| | | public static void insertNextPageChar(XWPFDocument document) { |
| | | XWPFParagraph paragraph = document.createParagraph(); |
| | | |
| | | |
| | | CTPPr ctpPr = paragraph.getCTP().addNewPPr(); |
| | | |
| | | |
| | | ctpPr.addNewSectPr(); |
| | | } |
| | | private static String delDynList(String placeholder, List obj, XWPFParagraph oldParagraph, XWPFDocument templateDoc) { |
| | | |
| | | private static String delDynList(String placeholder, List obj, XWPFParagraph oldParagraph, XWPFDocument templateDoc,Integer flag) { |
| | | String placeholderValue = placeholder; |
| | | List dataList = obj; |
| | | Collections.reverse(dataList); |
| | | //普通换行降序处理 表格换行无需降序 |
| | | if(flag == 0){ |
| | | Collections.reverse(dataList); |
| | | } |
| | | XWPFRun oldRun = oldParagraph.getRuns().size() > 0 ? oldParagraph.getRuns().get(0) : null; |
| | | Boolean isBold = Objects.nonNull(oldRun) ? oldRun.isBold() : false; |
| | | for (int i = 0, size = dataList.size(); i < size; i++) { |
| | | Object text = dataList.get(i); |
| | | |
| | | |
| | | if (i == 0) { |
| | | placeholderValue = String.valueOf(text); |
| | | } else { |
| | | XWPFParagraph paragraph = createParagraph(oldParagraph, templateDoc, oldRun, isBold, String.valueOf(text)); |
| | | XWPFParagraph paragraph = null; |
| | | if(flag == 0){ |
| | | paragraph = createParagraph(oldParagraph, templateDoc, oldRun, isBold, String.valueOf(text)); |
| | | }else if(flag == 1){ |
| | | paragraph = createTableRun(oldParagraph, oldRun, isBold, String.valueOf(text)); |
| | | } |
| | | |
| | | if (paragraph != null) { |
| | | oldParagraph = paragraph; |
| | | } |
| | |
| | | } |
| | | return placeholderValue; |
| | | } |
| | | |
| | | |
| | | public static XWPFParagraph createParagraph(XWPFParagraph oldParagraph, XWPFDocument templateDoc, XWPFRun oldRun, boolean isBold, String... texts) { |
| | | |
| | | |
| | | XmlCursor cursor = oldParagraph.getCTP().newCursor(); |
| | | XWPFParagraph newPar = templateDoc.insertNewParagraph(cursor); |
| | | |
| | | |
| | | newPar.getCTP().setPPr(oldParagraph.getCTP().getPPr()); |
| | | copyParagraph(oldParagraph, newPar, oldRun, isBold, texts); |
| | | return newPar; |
| | | } |
| | | |
| | | ; |
| | | |
| | | /** |
| | | * 创建table表格换行 段落run |
| | | * @param oldParagraph |
| | | * @param oldRun |
| | | * @param isBold |
| | | * @param texts |
| | | * @return |
| | | */ |
| | | public static XWPFParagraph createTableRun(XWPFParagraph oldParagraph,XWPFRun oldRun, boolean isBold, String... texts) { |
| | | |
| | | XWPFRun run = oldParagraph.createRun(); |
| | | run.addBreak(); |
| | | run.setText(texts[0]); |
| | | run.setFontFamily(oldRun.getFontFamily()); |
| | | int fontSize = oldRun.getFontSize(); |
| | | run.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize); |
| | | run.setBold(isBold); |
| | | run.setItalic(oldRun.isItalic()); |
| | | run.setColor(oldRun.getColor()); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | private static void copyParagraph(XWPFParagraph sourcePar, XWPFParagraph targetPar, XWPFRun oldRun, boolean isBold, String... texts) { |
| | | targetPar.setAlignment(sourcePar.getAlignment()); |
| | | targetPar.setVerticalAlignment(sourcePar.getVerticalAlignment()); |
| | | |
| | | |
| | | targetPar.setAlignment(sourcePar.getAlignment()); |
| | | targetPar.setVerticalAlignment(sourcePar.getVerticalAlignment()); |
| | | if (texts != null && texts.length > 0) { |
| | | String[] arr = texts; |
| | | |
| | | |
| | | for (int i = 0, len = texts.length; i < len; i++) { |
| | | String text = arr[i]; |
| | | XWPFRun run = targetPar.createRun(); |
| | | run.setText(text); |
| | | |
| | | |
| | | run.setFontFamily(oldRun.getFontFamily()); |
| | | int fontSize = oldRun.getFontSize(); |
| | | run.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize); |
| | |
| | | jaqTableStyle.setTableNum(tableNum); |
| | | Map<Integer, String> rowColorMap = new HashMap<>(); |
| | | jaqTableStyle.setRowColorMap(rowColorMap); |
| | | |
| | | |
| | | for (Integer i = 1; i <= inum; i++) { |
| | | if (Objects.equals(textMap.get(line + i.toString() + "C"), "1")) { |
| | | rowColorMap.put(i, "C00000"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | if (CollUtil.isNotEmpty(rowColorMap)) { |