0

i am inserting a wordMl on my current selection range

here is the wordMl i want to insert

<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
  <pkg:part pkg:name="/word/afchunk2.docx" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" />
  <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
    <pkg:xmlData>
      <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
        <w:body>
          <w:p>
            <w:r>
              <w:t></w:t>
            </w:r>
          </w:p>
          <w:altChunk r:id="AltChunkId1" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
        </w:body>
      </w:document>
    </pkg:xmlData>
  </pkg:part>
  <pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
    <pkg:xmlData>
      <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
        <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/afchunk2.docx" Id="AltChunkId1" />
      </Relationships>
    </pkg:xmlData>
  </pkg:part>
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
    <pkg:xmlData>
      <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
        <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/word/document.xml" Id="R1ff464e618a64ac8" />
      </Relationships>
    </pkg:xmlData>
  </pkg:part>
</pkg:package>

but when i insert it using

range.insertXml method it throws following exception message

"XML markup cannot be inserted in the specified location."

i have created document using openXml sdk.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445

1 Answers1

0

You can't directly add XML that was created using the OpenXML SDK. You need to convert your document package (WordprocessingDocument) to the Flat OPC Format, which is the format that range.InsertXml is expecting.

More Info: http://blogs.msdn.com/b/ericwhite/archive/2008/09/29/the-flat-opc-format.aspx

Jermismo
  • 230
  • 4
  • 8