Hello. I’m writing an application that takes a user-created template and inserts data into it. I am accomplishing this using merge fields and merge field regions. There are multiple templates in each file, for different types of data so the user can decide how they want each type to be displayed. Here is an example template region:
«TemplateStart:DEFAULTTEMPLATE»
«description»
Relationships:«relationships»
«TemplateEnd:DEFAULTTEMPLATE»
I iterate through the document and strip out these templates and put them into seperate Aspose Words Documents in memory, in a map. I then iterate through all the data that needs to be put into the document. I copy the template I extracted to a temporary Document, execute a merge, and then copy the result into the original document. This is so that the title page, table of contents, header/footer, etc… of the original document are retained.
This all works reasonably well, styles are correctly maintained, etc… However, a lot of extra paragraph breaks are inserted. I believe it has something to do with the fact that I am copying full Documents into the original Document multiple times.
Also, part of my copyDocument method sets the sectionStart to SectionStart.CONTINUOUS, because otherwise it defaults to a page break. I would prefer that everything be in the same section. Again, I think this has something to do with copying to a temporary document and back.
So I guess my question is whether or not there is an easy way to remove these extra paragraphs and merge sections, or if there is a better way for me to extract/store/insert these templates. I’ve attached the relevant code and an example template and output. Thank you in advance for your help!
-Dylan Gulick
Jama Software