我正在使用 Java 中的 DOCx4j 库创建一个 docx 文件。我创建了在 Libra Office 中完美显示的页脚,但在 MS-Word 2016 中没有显示。
页脚代码:
public static Relationship createFooterPageNumPart(
WordprocessingMLPackage wordprocessingMLPackage) throws Exception {
FooterPart footerPart = new FooterPart();
MainDocumentPart t = wordprocessingMLPackage.getMainDocumentPart();
footerPart.setPackage(wordprocessingMLPackage);
// footerPart.setJaxbElement(createFooterWithPageNr());
footerPart.setJaxbElement(createFooterWithPageNr(wordprocessingMLPackage,footerPart));
return t.addTargetPart(footerPart);
}
public static Ftr createFooterWithPageNr(WordprocessingMLPackage wordprocessingMLPackage, Part sourcePart) throws Exception {
Ftr ftr = objectFactory.createFtr();
P paragraph = objectFactory.createP();
RPr fontRPr = getRPr(objectFactory, "Frutiger LT Arabic 45 Light", "000000", "20", STHint.EAST_ASIA,
false, false, false, false);
R run = objectFactory.createR();
run.setRPr(fontRPr);
paragraph.getContent().add(run);
setParagraphAlign(objectFactory, paragraph, JcEnumeration.RIGHT);
ftr.getContent().add(paragraph);
return ftr;
}
public static void createFooterReference(
WordprocessingMLPackage wordprocessingMLPackage,
Relationship relationship)
throws InvalidFormatException {
List<SectionWrapper> sections = wordprocessingMLPackage
.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = objectFactory.createSectPr();
wordprocessingMLPackage.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = objectFactory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
请帮助我找出问题所在。