diff --git a/com.awspaas.user.apps.coe.pal.output.zd/lib/com.awspaas.user.apps.coe.pal.output.zd.jar b/com.awspaas.user.apps.coe.pal.output.zd/lib/com.awspaas.user.apps.coe.pal.output.zd.jar index 52d00463..58fdf927 100644 Binary files a/com.awspaas.user.apps.coe.pal.output.zd/lib/com.awspaas.user.apps.coe.pal.output.zd.jar and b/com.awspaas.user.apps.coe.pal.output.zd/lib/com.awspaas.user.apps.coe.pal.output.zd.jar differ diff --git a/com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java b/com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java index 06abb4eb..f145f5c3 100644 --- a/com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java +++ b/com.awspaas.user.apps.coe.pal.output.zd/src/com/awspaas/apps/coe/pal/output/zd/InstitutionalTextWeb.java @@ -452,8 +452,6 @@ public class InstitutionalTextWeb extends ActionWeb { if (suffix.equals("xml")) { // 输出文档路径及名称 - - File sourceFile = new UtilFile(path + fileName); File targetFile = new UtilFile(docPath + fileName); try { @@ -475,52 +473,6 @@ public class InstitutionalTextWeb extends ActionWeb { } - //获取section - /*Section section1 = doc1.getSections().get(0); - - //获取文档1的页眉页脚 - HeaderFooter headerword = section1.getHeadersFooters().getHeader(); - HeaderFooter footerword = section1.getHeadersFooters().getFooter(); - - //加载文档2 - com.sini.com.spire.doc.Document doc2 = new com.sini.com.spire.doc.Document(); - - - doc2.loadFromFile(outFile.getPath()); - - - //获取第一节 - Section sec = doc2.getSections().get(0); - - //删除页眉 - sec.getHeadersFooters().getHeader().getChildObjects().clear(); - - //删除页脚 - sec.getHeadersFooters().getFooter().getChildObjects().clear(); - - //遍历文档2的section - for (int i = 0; i < doc2.getSections().getCount(); i++) { - Section section2 = doc2.getSections().get(i); - //遍历页眉中的对象 - for (int j = 0; j < headerword.getChildObjects().getCount(); j++) { - //获取页眉中的所有子对象 - Object object1 = headerword.getChildObjects().get(j); - //复制文档1的页眉添加到文档2 - section2.getHeadersFooters().getHeader().getChildObjects().add(((DocumentObject) object1).deepClone()); - } - - //同理复制页脚 - for (int z = 0; z < footerword.getChildObjects().getCount(); z++) { - Object object2 = footerword.getChildObjects().get(z); - section2.getHeadersFooters().getFooter().getChildObjects().add(((DocumentObject) object2).deepClone()); - } - } - - doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); - - doc2.dispose();*/ - - //创建 Document 类的对象并从磁盘加载 Word 文档 com.sini.com.spire.doc.Document document = new com.sini.com.spire.doc.Document(outFile.getPath()); @@ -538,26 +490,24 @@ public class InstitutionalTextWeb extends ActionWeb { paragraphFormat.setHorizontalAlignment(HorizontalAlignment.Left); TextRange tr = paragraph.appendText("1.目的"); - - tr.getCharacterFormat().setBold(true); tr.getCharacterFormat().setFontName("宋体"); tr.getCharacterFormat().setFontSize(12); - paragraph.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 + paragraph.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 CharacterFormat format = new CharacterFormat(document); - format.setFontName("黑体"); + format.setFontName("宋体"); + format.setFontSize(12); //添加段落 Paragraph Purposeparagraph = section.addParagraph(); - Purposeparagraph.appendText(dataMap.getString("pl_Purpose")); - - - //获取第三段并设置首行缩进 - Paragraph para3 = section.getParagraphs().get(2); - para3.getFormat().setFirstLineIndent(30); + if (UtilString.isNotEmpty(dataMap.getString("pl_Purpose"))) { + Purposeparagraph.appendText(dataMap.getString("pl_Purpose")); + } else { + Purposeparagraph.appendText("无").applyCharacterFormat(format); + } //添加段落 Paragraph paragraph1 = section.addParagraph(); @@ -571,7 +521,7 @@ public class InstitutionalTextWeb extends ActionWeb { tr1.getCharacterFormat().setBold(true); tr1.getCharacterFormat().setFontName("宋体"); tr1.getCharacterFormat().setFontSize(12); - paragraph1.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 + paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 PALRepositoryPropertyModel term = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "term"); @@ -605,8 +555,6 @@ public class InstitutionalTextWeb extends ActionWeb { if (termTable != null && !termTable.isEmpty()) { String[][] strArray2 = new String[termTable.size()][]; - - List list = new LinkedList<>(); for (int i = 0; i < termTable.size(); i++) { JSONObject obj2 = termObj.getJSONArray("table").getJSONObject(i); @@ -645,8 +593,9 @@ public class InstitutionalTextWeb extends ActionWeb { dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); } } - - + } else { + Paragraph termparagraph = section.addParagraph(); + termparagraph.appendText("无").applyCharacterFormat(format); } @@ -662,7 +611,7 @@ public class InstitutionalTextWeb extends ActionWeb { tr2.getCharacterFormat().setBold(true); tr2.getCharacterFormat().setFontName("宋体"); tr2.getCharacterFormat().setFontSize(12); - paragraph2.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 + paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 JSONArray organizationTable = new JSONArray(); //组织职责Table @@ -690,8 +639,8 @@ public class InstitutionalTextWeb extends ActionWeb { //定义表格数据 String[] orgheader = {"组织", "职责"}; - if (organizationTable != null && !organizationTable.isEmpty()) { + if (organizationTable != null && !organizationTable.isEmpty()) { String[][] strArray2 = new String[organizationTable.size()][]; List list = new LinkedList<>(); @@ -733,8 +682,9 @@ public class InstitutionalTextWeb extends ActionWeb { dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); } } - - + } else { + Paragraph orgparagraph = section.addParagraph(); + orgparagraph.appendText("无").applyCharacterFormat(format); } @@ -750,23 +700,102 @@ public class InstitutionalTextWeb extends ActionWeb { tr3.getCharacterFormat().setBold(true); tr3.getCharacterFormat().setFontName("宋体"); tr3.getCharacterFormat().setFontSize(12); - paragraph3.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 + paragraph3.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 - if (suffix.equals("xml")) { - //保存为xml格式 - String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); - //保存为Word - document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013); - } else { - document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); + // 删除第一段落 + if (document.getSections().getCount() > 0) { + Section section4 = document.getSections().get(0); + if (section4.getParagraphs().getCount() > 0) { + section4.getParagraphs().removeAt(0); + } } - - // document.insertTextFromFile("/Users/sunlh/Downloads/手册格式问题测试文档(3)new.docx", FileFormat.Docx_2013); //保存结果文档 document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + String appendUrl = null; + if (suffix.equals("xml")) { + //保存为xml格式 + String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + appendUrl = docPath + substring + ".docx"; + } else { + document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); + appendUrl = path + fileName; + } + + com.sini.com.spire.doc.Document document2 = new com.sini.com.spire.doc.Document(appendUrl); + + int sectionCount = document.getSections().getCount(); + ProcessInstance boProcessInstance = SDK.getProcessAPI() + .createBOProcessInstance("obj_70c7c5eb0e8f425fa1b57a94038089a8", "admin", "页面方向"); + + // 判断文档中是否存在横向页面方向 + boolean isLandscape = false; + // 循环遍历每个节(Section) + for (int i = 0; i < sectionCount; i++) { + Section souresection = document.getSections().get(i); + + // 获取当前节的页面方向 + PageSetup pageSetup = souresection.getPageSetup(); + PageOrientation pageOrientation = pageSetup.getOrientation(); + + if (pageSetup.getOrientation() == PageOrientation.Landscape) { + isLandscape = true; + break; // 如果存在横向页面方向,则跳出循环 + } + } + + if (isLandscape) { + System.out.println("文档存在横向页面方向"); + + if (suffix.equals("xml")) { + //保存为xml格式 + String substring = fileName.substring(0, fileName.lastIndexOf(".xml")); + //保存为Word + document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013); + } else { + document.insertTextFromFile(path + fileName, FileFormat.Docx_2013); + } + //保存结果文档 + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + BO bo = new BO(); + bo.set("FILENAME", fileName); + bo.set("PALID", repositoryId); + bo.set("PAGE_ORIENTATION", "横向"); + SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), ""); + + } else { + + System.out.println("文档存在纵向页面方向"); + + //在第二个文档中循环获取所有节 + for (Object sectionObj : (Iterable) document2.getSections()) { + Section sec = (Section) sectionObj; + //在所有节中循环获取所有子对象 + for (Object docObj : (Iterable) sec.getBody().getChildObjects()) { + DocumentObject obj = (DocumentObject) docObj; + + //获取第一个文档的最后一节 + Section lastSection = document.getLastSection(); + + //将所有子对象添加到第一个文档的最后一节中 + Body body = lastSection.getBody(); + body.getChildObjects().add(obj.deepClone()); + } + } + //保存结果文档 + document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); + + + BO bo = new BO(); + bo.set("FILENAME", fileName); + bo.set("PALID", repositoryId); + bo.set("PAGE_ORIENTATION", "纵向"); + SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), ""); + + } } } long b2 = System.currentTimeMillis(); @@ -791,23 +820,27 @@ public class InstitutionalTextWeb extends ActionWeb { ParagraphFormat paragraphFormat3 = paragraph3.getFormat(); paragraphFormat3.setHorizontalAlignment(HorizontalAlignment.Left); - TextRange tr3 = paragraph3.appendText("5.附则"); + TextRange tr3 = paragraph3.appendText("附则"); tr3.getCharacterFormat().setBold(true); tr3.getCharacterFormat().setFontName("宋体"); tr3.getCharacterFormat().setFontSize(12); - paragraph3.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式 + paragraph3.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 CharacterFormat format = new CharacterFormat(document); - format.setFontName("黑体"); + format.setFontName("宋体"); format.setFontSize(12); //添加段落 Paragraph articlesparagraph = section.addParagraph(); - articlesparagraph.appendText(dataMap.getString("pl_T_supplementary_articles")).applyCharacterFormat(format); + if (UtilString.isNotEmpty(dataMap.getString("pl_T_supplementary_articles"))) { + articlesparagraph.appendText(dataMap.getString("pl_T_supplementary_articles")); + } else { + articlesparagraph.appendText("无").applyCharacterFormat(format); + } document.saveToFile(outFile.getPath(), FileFormat.Docx_2013); @@ -841,8 +874,8 @@ public class InstitutionalTextWeb extends ActionWeb { HeaderFooter sourceHeader = sourceSection.getHeadersFooters().getHeader(); HeaderFooter sourceFooter = sourceSection.getHeadersFooters().getFooter();*/ - // 将页眉复制到目标文档的第三节以及后续节 - for (int i = 2; i < doc2.getSections().getCount(); i++) { + // 将页眉复制到目标文档的第一节以及后续节 + for (int i = 0; i < doc2.getSections().getCount(); i++) { Section targetSection = doc2.getSections().get(i); PageSetup pageSetup = targetSection.getPageSetup(); @@ -865,8 +898,8 @@ public class InstitutionalTextWeb extends ActionWeb { targetHeader.getChildObjects().add(obj); } } - // 将页脚复制到目标文档的第三节以及后续节 - for (int i = 2; i < doc2.getSections().getCount(); i++) { + // 将页脚复制到目标文档的第一节以及后续节 + for (int i = 0; i < doc2.getSections().getCount(); i++) { Section targetSection = doc2.getSections().get(i); HeaderFooter targetFooter = targetSection.getHeadersFooters().getFooter(); @@ -882,167 +915,15 @@ public class InstitutionalTextWeb extends ActionWeb { targetFooter.getChildObjects().add(obj); } } + + doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); return outFile.getPath(); } - /** - * 获取条款内容xml - * - * @param repositoryId - * @param controlShapeId - * @return - */ - /*private Map getContentData(String repositoryId, String controlShapeId) throws Exception { - Map result = new HashMap<>(); - result.put("listDef", ""); - result.put("content", ""); - if (UtilString.isEmpty(controlShapeId)) { - return result; - } - PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId); - if (repositoryModel == null) { - return result; - } - String content = ""; - StringBuilder listStr = new StringBuilder(); - // 读取附件 - // 流程附件列表 - UpFileDao upFileDao = new UpFileDao(); - List search = upFileDao.search(repositoryModel.getId(), controlShapeId, null); - DCContext dcContextpdf = null; - File file = null; - if (search != null && search.size() > 0) { - // 复制附件 - for (UpfileModel upfileModel : search) { - DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); - if (upfileModel.getFileName().contains(".xml")) { - if (dcProfile != null) { - dcContextpdf = new DCContext(_uc, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); - *//* - * String path = dcContextpdf.getPath(); String fileName = - * dcContextpdf.getFileName(); com.spire.doc.Document docs = new - * com.spire.doc.Document(); docs.loadFromFile("/"+path+fileName); String - * substring = fileName.substring(0, fileName.lastIndexOf(".xml")); - * docs.saveToFile("/"+path+substring+".xml",FileFormat.Word_ML); dcContextpdf = - * new DCContext(userContext, dcProfile, CoEConstant.APP_ID, - * upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), substring+".xml"); - *//* - break; - } - } - if (upfileModel.getFileName().contains(".doc") || upfileModel.getFileName().contains(".docx")) { - if (dcProfile != null) { - dcContextpdf = new DCContext(_uc, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName()); - String path = dcContextpdf.getPath(); - String fileName = dcContextpdf.getFileName(); - //创建实例,加载doc测试文档 - String s = path + fileName; - - - com.sini.com.spire.doc.Document docs = new com.sini.com.spire.doc.Document(); - - - docs.loadFromFile(path + fileName); - //保存为xml格式 - String substring = fileName.substring(0, fileName.lastIndexOf(".doc")); - docs.saveToFile(path + substring + ".xml", FileFormat.Word_Xml); - - dcContextpdf = new DCContext(_uc, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), substring + ".xml"); - break; - } - } - - } - } - if (dcContextpdf != null) { - file = new File(dcContextpdf.getFilePath()); - } - if (file != null) { - // 解析xml文件 - // 校验xml文档是否能够正常解析 - Document doc = analysisXMLFile(file.getPath(), true); - if (doc == null) { - System.out.println("解析xml失败"); - return null; - } - int step = 20;// 以20为步长进行批量调整 - // 解析根节点 - Element root = doc.getRootElement(); - - // System.out.println(root.getName()); - Element lists = root.element("lists"); - if (lists != null) { - for (Object obj : lists.elements()) { - Element e = (Element) obj; - String name = e.getName(); - if ("listDef".equals(name)) { - e.setAttributeValue("listDefId", Integer.parseInt(e.attributeValue("listDefId")) + step + ""); - listStr.append(e.asXML()); - } - if ("list".equals(name)) { - e.setAttributeValue("ilfo", Integer.parseInt(e.attributeValue("ilfo")) + step + ""); - Element ilst = e.element("ilst"); - ilst.setAttributeValue("val", Integer.parseInt(ilst.attributeValue("val")) + step + ""); - listStr.append(e.asXML()); - } - } - } - - - // 获取字符串 - content = getFileContent(file); - // content = content.substring(content.indexOf("") + 9, content.indexOf("") + 8, content.indexOf("")); - String[] arr = content.split(""); - StringBuilder tmp = new StringBuilder(); - for (int i = 0; i < arr.length; i++) { - tmp.append(arr[i].substring(arr[i].indexOf("") + 9)); - } - content = tmp.toString(); -// System.out.println(content); -// System.out.println("以上的是替换前文本,以下是替换后文本"); - String[] contentArr = content.split(" list = Arrays.asList(contentArr); - content = StringUtils.join(list, " regulateSet = new HashSet();// 控制 Set KPISet = new HashSet();// kpi - List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容 + /*List> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容 if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序 OutputWordUtil.orderByNumber(repositoryFileElements); - } + }*/ //组织和职责