Open Xml PowerTool to merge the two content in same word

Home Forums Open-Xml-PowerTools Open Xml PowerTool to merge the two content in same word

This topic contains 1 reply, has 2 voices, and was last updated by  Brant 5 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #7419

    Qwerty
    Participant

    I have used PowerTool to merge my two word document using DocumentBuilder. But its merging them in as different pages. I want to merge the second word content in the next line of content of first document content. Below is my code.
    ` List<Source> sources = new List<Source>();

    sources.Add(new Source(@”C:\Temp\Word1.docx”, true));

    sources.Add(new Source(@”C:\Temp\Word2.docx”, true));

    DocumentBuilder.BuildDocument(sources, @”C:\Temp\MergedDoc.docx”);

    Whats Happening:
    Word1 Content
    <—Page Break —>
    Word2 Content

    Whats Expected:
    Word1 Content
    Word2 Content

    Thanks in advance

    #7515

    Brant
    Participant

    Source has another constructor that allows you to specify the child elements of <w:body> to include in the final document.

    public Source(WordprocessingDocument source, int start, int count, bool keepSections);

    This is from Eric’s blog: How to Control Sections when using OpenXml.PowerTools.DocumentBuilder

    A super-short summary of how you use DocumentBuilder: to assemble a new document, you open any number of source Open XML WordprocessingML documents, then assemble a List<OpenXml.PowerTools.Source>, where members of the list are Source objects that you construct, passing a number of parameters. There are three overloads of the Source constructor:

    public Source(WordprocessingDocument source, bool keepSections)
    public Source(WordprocessingDocument source, int start, bool keepSections)
    public Source(WordprocessingDocument source, int start, int count, bool keepSections)

    The first parameter is the open WordprocessingML source document.

    If you use the first overload, then the entire source document is copied (along with all dependencies) to the destination document. If you use the second overload, you can specify a starting paragraph (technically the starting child element of the w:body element), and the document from that point on is copied to the destination document. The third overload allows you to pluck just a subsection of the source document for inclusion in the destination document.

    The last parameter is always a bool, keepSections. You can specifically control how sections are copied to the newly-built document using the keepSections argument.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.