how use docx to process OLE object?

May 27, 2013 at 2:27 AM
How use docx to processing OLE object?Thank you.
Oct 20, 2014 at 7:54 PM
In the current version public void InsertDocument(DocX remote_document) cannot copy over a document with an OLE object in it properly. It will copy, but if you open the document Word will complain the document is badly formatted.

This appears to be due to the id's not being updated when copied over.

Adding the following to public void InsertDocument(DocX remote_document) right after fixing up the hyper links, will fix this situation with the one docx file I have found thus far that had a Word drawing embedded in it as an OLE object. This may not work for all situations because I'm unsure if the namespace urn:schemas-microsoft-com:office:office covers all OLE objects.
foreach (var oleObject_rel in remote_document.mainPart.GetRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"))
{
    var old_rel_Id = oleObject_rel.Id;
    var new_rel_Id = mainPart.CreateRelationship(oleObject_rel.TargetUri, oleObject_rel.TargetMode, oleObject_rel.RelationshipType).Id;
    var oleObject_refs = remote_mainDoc.Descendants(XName.Get("OLEObject", "urn:schemas-microsoft-com:office:office"));
    foreach (var oleObject_ref in oleObject_refs)
    {
        XAttribute a0 = oleObject_ref.Attribute(XName.Get("id", DocX.r.NamespaceName));
        if (a0 != null && a0.Value == old_rel_Id)
        {
            a0.SetValue(new_rel_Id);
        }
    }
}