none
edit open xml in a word Document project RRS feed

  • Question

  •  

    Hello,

     

    I would like to know if it's possible to edit the open xml in a word document project (word 2007). I know it's possible to access it via the "WordOpenXML"  property but it's read only. Is there a way to edit the open xml ?

     

    Thank you in advance for any help.

     

    mathmax

    Tuesday, December 25, 2007 4:16 PM

Answers

  • Hi mathmax

     

    Look at the InsertXML and XML properties of the Word.Range object. That will let you work with the XML of an open document during automation of that document.

     

     

    Wednesday, January 2, 2008 5:03 PM
    Moderator

All replies

  • Hi MathMax,

     

    Based on my experience, via Word Object Model, this cannot be done. Manipulating document with OpenXML is not the designed purpose of Word Object Model.

    To manipulate a document with OpenXML, the common way is to use System.IO.Packaging, as described in the following link:

    http://msdn2.microsoft.com/en-us/library/aa982683.aspx

    But there is no guarantee that it would work in your scenario, for the current VSTO document is opened and locked by Word. So my guess is we may receive “File is in use” exception when we try to do that. This should also be the reason why WordOpenXML property is designed to be read-only.

    If you want to manipulate document with OpenXML, maybe you need to consider about Office Automation, but not VSTO.

     

     

    Thanks

    Ji

     

    Wednesday, December 26, 2007 9:10 AM
    Moderator
  • Hi mathmax

     

    Look at the InsertXML and XML properties of the Word.Range object. That will let you work with the XML of an open document during automation of that document.

     

     

    Wednesday, January 2, 2008 5:03 PM
    Moderator