Docx4j页脚未显示在MS-Word 2016中 [英] Docx4j Footer not showing in MS-Word 2016

查看:201
本文介绍了Docx4j页脚未显示在MS-Word 2016中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java中的DOCx4j库创建docx文件.我创建的页脚在Libra Office中可以完美显示,但在MS-Word 2016中却不显示.

I am creating a docx file using DOCx4j Library in Java. I have created the Footer which is showing perfectly in Libra Office but it is not showing in 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);
    }

请帮助我找出问题所在.

Please help me out in finding where it is going wrong.

推荐答案

您的docx开头为:

<w:body>
    <w:sectPr>
        <w:headerReference w:type="default" r:id="rId4"/>
    </w:sectPr>

结尾为:

    <w:sectPr>
        <w:footerReference w:type="default" r:id="rId5"/>

尝试将w:headerReference从sectPr的开头(几乎没有意义)移动到结尾的那个.

Try moving w:headerReference from the sectPr at the beginning (which makes little sense) to the one at the end.

但是根据Word 2016,您发布的docx已损坏,因此还有其他问题需要解决.

But according to Word 2016, the docx you posted is broken, so it has other issues which need to be addressed.

这篇关于Docx4j页脚未显示在MS-Word 2016中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆