Merging two documents and setting a sectionbreak odd page between them
Home › Forums › WordprocessingML › Merging two documents and setting a sectionbreak odd page between them
This topic contains 2 replies, has 2 voices, and was last updated by Samo 8 years, 9 months ago.
-
AuthorPosts
-
March 24, 2016 at 10:59 am #3266
Hello Mr White,
I hope we could continue the Thread that i started in the old forums
http://openxmldeveloper.org/discussions/formats/f/13/t/8574.aspxthank you for your reply and apologies for the late reply from myself.
I looked into the document builder and it is a very nice tool for keeping headers and sections in the merged document.
The section break thing is still giving me some problems though:
My example looks like this
List<Source> list = new List<Source>();
list.Add(new Source(stream1, true));
list.Add(new Source(“c:\\Temp\\SectionBreakOdd.docx”, true));
list.Add(new Source(stream2, true));
list.Add(new Source(“c:\\Temp\\SectionBreakOdd.docx”, true));
list.Add(new Source(stream3, true));
list.Add(new Source(“c:\\Temp\\SectionBreakOdd.docx”, true));
list.Add(new Source(stream4, true));
DocumentBuilder.BuildDocument(list, “c:\\temp\\result.docx”);
Unfortunately, this does not work too well. I guess the problem arises with keeping the old sections in the source documents and then appending the dummy document with the odd section break.
Is there any chance to make this work?
Kind regards,
Samo
March 24, 2016 at 12:10 pm #3267Yes, keeping the sections in the other sources will definitely put those sections in the generated document, and a section is defined as the content between it and the previous section, per the spec.
If you really need to control the very specific properties of each section, then run DocumentBuilder in a loop – add a document – and then tweak the last section in the document, add the next document, and then tweak the last section, and repeat until you have added all of your documents. By tweaking the last w:sectPr in the document, you write a bit of code to go in and make the necessary changes to the property, and save the document.
It is still going to be very fast – what kind of volumes do you anticipate? It runs in the hundreds of documents per second, if I recall correctly.
If you review the screen-cast on sections, headers, and footers, you will recall that the last section props is the last child element of the w:body element, so it is easy to get to the last section.
March 24, 2016 at 1:05 pm #3269Hello,
thanks for the suggestion. The number of documents to append will be low, usually 2 to 5 with a couple of pages in each document. So i do not think that speed will be an issue.
So do i understand the workflow right?
I should grab the first document, then manipulate the last section prop and append the next document via the documentbuilder.
Then build the document and repeat the procedure for the remaining documents to append.I will give this a try and report back, thanks so far 🙂
-
AuthorPosts
You must be logged in to reply to this topic.