Insert Document (.docx) in existing document

Home Forums Open-Xml-PowerTools Insert Document (.docx) in existing document

This topic contains 2 replies, has 2 voices, and was last updated by  Eric White 7 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3369

    Thierry
    Participant

    Hi Eric,

    I am using Open XML PowerTools Version 4.2.
    I do have a problem with the inserting an existing document into a document on a special location by using Id in the ‘Source’-constructor. They way I would like to do this is by inserting a content control with a specific unique Id and the replacing the content paragraph of the content control with: sdtContentPar.ReplaceWith(New XElement(PtOpenXml.Insert, New XAttribute(“Id”, “InsertFile”))) where stdContentPar is declared as XElement.

    Sample code (taken from the sample DocumentBuilder01):

    string source1 = “../../Flow.docx”;
    string source2 = “../../~mvi52qa2vp.docx”;
    List<Source> sources = null;
    sources = new List<Source>()
    {
    new Source(new WmlDocument(source1), true),
    new Source(new WmlDocument(source2), “InsertFile”)
    };
    DocumentBuilder.BuildDocument(sources, Path.Combine(tempDi.FullName, “Out3.docx”));

    I get an ‘InvalidOperationException’ on the following line with ‘var p = s.SiblingsBeforeSelfReverseDocumentOrder().First();’ in the method ‘FixUpSectionProperties’.
    The method s.SiblingsBeforeSelfReverseDocumentOrder() returns null, but I don’t understand why I get this returns null (which is causing the exception) and I hope you can give me some support.

    I understand that you cannot research this by having the source documents (Flow.docx and ~mvi52qa2vp.docx”), but I currently I don’t see a way the post these documents.

    I hope you can support me with this.

    Kind regards,
    Thierry

    #3370

    Thierry
    Participant

    Hi Eric,

    Eventually, I have found the problem.
    The element of the ‘SectionProperties’ should be the last element of the <Body>-element and not the first element 🙂

    Cheers,
    Thierry

    #3372

    Eric White
    Keymaster

    Hi Thierry,

    Glad you got the issue resolved.

    I don’t currently have a way to attach a document to a forum post. For now, what I ask is that when necessary to do this, put the document on DropBox or OneDrive, and put a link in the post. FYI.

    Even though you have the issue resolved, this does point out a bug – DocumentBuilder should not fail in this way, even if the section properties are in the wrong place.

    Cheers, Eric

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

You must be logged in to reply to this topic.