i'm trying to overwrite a footer of a document with potentally many sections with my own footer.
I use the following code, inspired by this and the HeaderFooterCreate sample. This is all footer-related code i wrote.
- Code: Select all
Ftr ftr = FACTORY.createFtr();
FooterPart footerPart;
Relationship relationship;
try
{
footerPart = new FooterPart();
footerPart.setPackage(wordprocessingMLPackage);
footerPart.setJaxbElement(ftr);
relationship = wordprocessingMLPackage.addTargetPart(footerPart);
}
catch (InvalidFormatException exception)
{
throw new RuntimeException(exception);
}
// ftr.getContent().clear();
// for (TextParagraphConfiguration textParagraphConfiguration : paragraphs)
// {
// P p = WordParagraphUtil.createParagraph(textParagraphConfiguration);
// p.getPPr().setSpacing(NO_SPACING);
// ftr.getContent().add(p);
// }
P p = FACTORY.createP();
ftr.getContent().add(p);
List<SectionWrapper> sections = wordprocessingMLPackage.getDocumentModel().getSections();
for (SectionWrapper sectionWrapper : sections)
{
SectPr sectPr = sectionWrapper.getSectPr();
// There is always a section wrapper, but it might not contain a
// sectPr
if (sectPr == null)
{
sectPr = FACTORY.createSectPr();
wordprocessingMLPackage.getMainDocumentPart().addObject(sectPr);
sectionWrapper.setSectPr(sectPr);
}
FooterReference footerReference = FACTORY.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
Where FACTORY is Context.getWmlObjectFactory();.
Is there anything I am doing wrong here, because the output document won't open in word failing at this line in document.xml:
![Image](http://www.imgbox.de/users/public/images/BPDiiORkLG.png)
The .rels file looks like
- Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Target="word/document.xml"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Id="rId1" />
<Relationship Target="docProps/core.xml"
Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Id="rId2" />
<Relationship Target="docProps/app.xml"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Id="rId3" />
<Relationship Target="word/footer.xml"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"
Id="rId4" />
</Relationships>
Thanks,
Francesco Silvani