Page 1 of 1

Adding XWPFParagraph to a MainDocumentPart

PostPosted: Sun Apr 01, 2018 1:15 pm
by justawolf
I'm trying to copy the paragraphs from one file to another.
Some of the paragraphs require some "processing" to morph the content
Others I just want to copy straight over.

I'm going through the content in the first file with a List of XWPFParagraph
List<XWPFParagraph> paragraphList = xdoc.getParagraphs();

For the paragraphs that I have to modify, I create a new P and add that to MainDocumentPart with addObject. These copy over fine since I'm not exactly copying but creating new content from the original.

For the paragraphs that I don't need to touch, how do I add each XWPFParagraph to the MainDocumentPart? I need to preserve all the formatting/styles within the paragraphs I'm not touching.

Thanks.

Re: Adding XWPFParagraph to a MainDocumentPart

PostPosted: Wed Apr 04, 2018 8:04 am
by jason
XWPFParagraph is a POI thing, you won't see those objects if you are opening a docx with docx4j.

Either you are in the wrong forum entirely, or you are using both POI and docx4j?

If you are using both POI and docx4j, the solution to interop would be to go from XWPFParagraph to XML (using XML Beans, I guess), then to use docx4j to unmarshall that w:p xml to docx4j's org.docx4j.wml.P