Hi Cory, It seems that you wish benefit with "mail merge" features. I suggest you that you try XDocReport <https://github.com/opensagres/xdocreport/wiki/DocxReportingQuickStart> which provides the capability to create a template docx with MS Word and use Velocity/Freemarker syntax to manage fields to replace (your need), manage loop (for section, etc), condition, etc by using a Java model.
You can too convert your generated docx to HTML and PDF (we load POI+iText for that, but it's not perfect). Hope it will help you. Regard's Angelo 2016-08-08 17:10 GMT+02:00 Cory Newey <cory.ne...@gmail.com>: > Thanks for the replies. > > Unfortunately, I don't just want to tack one document onto the end of > another document. I want to search for a particular word/phrase in the > first document and replace that with the entire contents of the second > document. That means that if I find the text to be replaced inside of a > particular run, I need to preserve all of the contents of the runs before > that run, insert all of the contents from the merged-in document at the > place where run that contains the text-to-be-replaced resides, and then > preserve all of the contents of the runs that come after. > > Thanks again. > ~Cory > > > On Mon, Aug 8, 2016 at 5:19 AM, Murphy, Mark <murphym...@metalexmfg.com> > wrote: > > > That depends on what you mean by merge. Are you just trying to append > > document B onto the end of Document A, or are you trying to mix them > > together in some specific way? > > > > Appending should be just a matter of reading through the document body of > > Document B, and copying the elements to Document A. I wouldn't look for > > just paragraphs, but all elements. That way you shouldn't lose anything. > > The main thing you will have to watch out for is sections. These aren't > > handled well right now (ok, not handled at all). If there is one section > in > > the document, the section element will be found at the end of the > document, > > and must remain there. If there are multiple sections, all but the last > > section element will be found in the last paragraph properties element of > > the section. > > > > Just remember, the Word interface is still unstable, and subject to > > significant changes. And there is still much that has to be accomplished > > down in the weeds of the CT_ interfaces. > > > > -----Original Message----- > > From: Cory Newey [mailto:cory.ne...@gmail.com] > > Sent: Sunday, August 07, 2016 4:30 PM > > To: user@poi.apache.org > > Subject: Merge Word docx into another Word dox via XWPFDocument - > > preserving formatting > > > > Hello All: > > > > I've tried to check the FAQ for this question and was unable to find > > anything. I'm not sure if this should be a question for the developers' > > list; I couldn't really tell from the brief description of the various > > lists. Anyway, I figured I'd ask the question here and you guys could > > bounce me over to the developers' list if that is the appropriate place > for > > this question. > > > > I have written a program that will merge changes (replace certain words > > with other words/phrases) into a Word (docx) document using XWPFDocument. > > But now I want to replace words/sections of one Word document with an > > entire other Word document. I've tried to update my program so that it > > iterates through the paragraphs/runs of the document to be merged in. It > > merges the text just fine but it loses all formatting, tables, etc. I've > > googled the question and found a few Stack-Overflow posts that talked > about > > it, but nothing was of any use to me. > > > > My question is: is it possible to merge one Word document into another > > Word document, such that it copies all formatting, tables, etc from the > > merged-in document (minus any headers/footers - that would be a little > > impossible I think) into the merged-into document - using the > XWPFDocument > > object? > > > > Thanks in advance for any help. > > ~Cory > > >