Page 1 of 1

merge document error - footers

PostPosted: Tue Jul 11, 2017 4:40 am
by sdeal
I'm having a similar issue. I'm trying to migrate a footer from one file into another file. First I create an ArrayList of all the FooterPart objects from the source file (in order: /word/footer1.xml, /word/footer3.xml, /word/footer2.xml), then iterate over them like this (the createFooterReference function is adapted from the sample code HeaderFooterCreate.java):

Code: Select all
for(FooterPart footerPart : footerParts){
   footerPart.setPackage(baseDocPackage);
   Relationship rel = baseDocPackage.getMainDocumentPart().addTargetPart(footerPart);
   baseDocPackage.getParts().put(footerPart);
   createFooterReference(baseDocPackage, rel);
}


I then get basically the same error Giuseppe originally posted, as the save function cannot find "/word/footer3.xml". Originally I didn't have the lines "footerPart.setPackage(...)" and "baseDocPackage.getParts().put(...)" but adding those doesn't seem to have made a difference.

When I debug through the code in Eclipse, it appears that the size of the baseDocPackage parts table is 16 to begin with. The first FooterPart (/word/footer1.xml) already exists in the destination file, so it is overwritten. When the second FooterPart is added (/word/footer3.xml), the parts table expands to 32 and a new FooterPart is added to "values" but not "table". The third FooterPart (/word/footer2.xml) is correctly added to both the "values" and "table". So, when it attempts to save, it appears there are three FooterPart objects in "values", but only two in "table". Could this be the source of my problem? Or is this totally irrelevant?

Thanks!
-Sean

Re: merge document error - footers

PostPosted: Wed Jul 12, 2017 7:45 am
by jason
Are you simply trying to replace the footers in the target document, or something more complex?

Note that footers are specified in sectPr elements, and there could be more than one sectPr...

I guess you should look at the addTargetPart code.