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 7a3e4a03..52d00463 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 1c7073ed..06abb4eb 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 @@ -827,41 +827,61 @@ public class InstitutionalTextWeb extends ActionWeb { //加载文档2 com.sini.com.spire.doc.Document doc2 = new com.sini.com.spire.doc.Document(); - - doc2.loadFromFile(outFile.getPath()); - SectionCollection sections = doc2.getSections(); + //加载文档1 + com.sini.com.spire.doc.Document doc3 = new com.sini.com.spire.doc.Document(); + doc3.loadFromFile(tempPath + "横板页眉页脚模板.doc"); + // 获取源文档的页眉页脚 - Section sourceSection = doc1.getSections().get(0); + /*Section sourceSection = doc1.getSections().get(0); HeaderFooter sourceHeader = sourceSection.getHeadersFooters().getHeader(); - HeaderFooter sourceFooter = sourceSection.getHeadersFooters().getFooter(); + HeaderFooter sourceFooter = sourceSection.getHeadersFooters().getFooter();*/ // 将页眉复制到目标文档的第三节以及后续节 - for (int i = 0; i < doc2.getSections().getCount(); i++) { + for (int i = 2; i < doc2.getSections().getCount(); i++) { Section targetSection = doc2.getSections().get(i); + + PageSetup pageSetup = targetSection.getPageSetup(); + PageOrientation orientation = pageSetup.getOrientation(); + + + // 根据合并文档节的页面方向选择模板 + PageOrientation mergeOrientation = pageSetup.getOrientation(); + com.sini.com.spire.doc.Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; + + // 复制模板文档的页眉和页脚到新文档 + HeaderFooter sourceHeader = templateDoc.getSections().get(0).getHeadersFooters().getHeader(); + HeaderFooter targetHeader = targetSection.getHeadersFooters().getHeader(); targetHeader.getChildObjects().clear(); + for (int j = 0; j < sourceHeader.getChildObjects().getCount(); j++) { + DocumentObject obj = sourceHeader.getChildObjects().get(j).deepClone(); targetHeader.getChildObjects().add(obj); } } - // 将页脚复制到目标文档的第三节以及后续节 - for (int i = 0; i < doc2.getSections().getCount(); i++) { + for (int i = 2; i < doc2.getSections().getCount(); i++) { Section targetSection = doc2.getSections().get(i); HeaderFooter targetFooter = targetSection.getHeadersFooters().getFooter(); + + PageSetup pageSetup = targetSection.getPageSetup(); + + PageOrientation mergeOrientation = pageSetup.getOrientation(); + com.sini.com.spire.doc.Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1; + HeaderFooter sourceFooter = templateDoc.getSections().get(0).getHeadersFooters().getFooter(); + targetFooter.getChildObjects().clear(); for (int j = 0; j < sourceFooter.getChildObjects().getCount(); j++) { DocumentObject obj = sourceFooter.getChildObjects().get(j).deepClone(); targetFooter.getChildObjects().add(obj); } } - doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013); diff --git a/com.awspaas.user.apps.coe.pal.output.zd/制度-手册6.xml b/com.awspaas.user.apps.coe.pal.output.zd/制度-手册6.xml index 36596558..4d534cf4 100644 --- a/com.awspaas.user.apps.coe.pal.output.zd/制度-手册6.xml +++ b/com.awspaas.user.apps.coe.pal.output.zd/制度-手册6.xml @@ -2739,7 +2739,7 @@ y7fdOgAAAABJRU5ErkJggk== - + diff --git a/com.awspaas.user.apps.coe.pal.output.zd/横板页眉页脚模板.doc b/com.awspaas.user.apps.coe.pal.output.zd/横板页眉页脚模板.doc new file mode 100644 index 00000000..1b045f1a Binary files /dev/null and b/com.awspaas.user.apps.coe.pal.output.zd/横板页眉页脚模板.doc differ