locked
Retrieving a Microsoft.Office.Interop.Word.Range object using OpenXml/WordprocessingDocument RRS feed

  • Question

  • Hi,

    i have need to be able to identify the Microsoft.Office.Interop.Word.Rane of objects found in my document using OpenXML.  Can this be donr?

    For instance, i have an addin that makes a copy of the currently open document, reads that temp copy to retrieve all the inlineshape sin the document and displays them in a listview to the user with attributes such as size and type.  Now depending on which image the user selects, i want to be able to identify it in the document they have open.  Given that i generated the list from a temp copy of the document that was processed using the openxml sdk, how can i at the time i am processing that temp document, also read at the very least the range start and end of each inline shape i read?

    Thanks much

     

    Thursday, October 7, 2010 11:01 PM

Answers

  • Hi Mark

    There isn't going to be any straight-forward way to do this. If we were talking about Shapes - those have a Name (and in 2010 an ID) property you could use to identify them.

    InlineShapes have neither of these things, so you have to get a bit creative.

    One possibility would be to store the Index value (position in the document StoryRange): InlineShapes(3).Range, for example.

    Another would be to place each InlineShape in a bookmark before your code creates the "temp doc". You can then access the InlineShape via the bookmark range: Bookmarks("NAmeOfBookmark").Range.InlineShapes(1)

    Possibly, you could have all the InlineShapes in their own Image Content Control and store the ID of the content control.


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Amy Li Wednesday, October 13, 2010 1:38 AM
    • Marked as answer by Amy Li Wednesday, October 13, 2010 8:05 AM
    Friday, October 8, 2010 8:02 AM

All replies

  • Hi Mark

    There isn't going to be any straight-forward way to do this. If we were talking about Shapes - those have a Name (and in 2010 an ID) property you could use to identify them.

    InlineShapes have neither of these things, so you have to get a bit creative.

    One possibility would be to store the Index value (position in the document StoryRange): InlineShapes(3).Range, for example.

    Another would be to place each InlineShape in a bookmark before your code creates the "temp doc". You can then access the InlineShape via the bookmark range: Bookmarks("NAmeOfBookmark").Range.InlineShapes(1)

    Possibly, you could have all the InlineShapes in their own Image Content Control and store the ID of the content control.


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Amy Li Wednesday, October 13, 2010 1:38 AM
    • Marked as answer by Amy Li Wednesday, October 13, 2010 8:05 AM
    Friday, October 8, 2010 8:02 AM
  • Hi mark010101,

    I'm writing to check the status of the thread. Could you please let me know if you have solved the problem?

    Best Regards,
    Amy Li


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Wednesday, October 13, 2010 1:38 AM
  • sorry for the late response. Yes i think this was helpful assuming the index is a reliable way of identifying the inline shape in the "real" document. Is that true?  in otherwords, if i have a document and copy of that same document, are the indexes of the inline shape in the two documents guaranteed to be the same if one of those document is open but the other is not (i.e. does work do any shifting around internally of indices for instance)?
    Monday, November 8, 2010 4:02 PM
  • sorry for the late response. Yes i think this was helpful assuming the index is a reliable way of identifying the inline shape in the "real" document. Is that true?  in otherwords, if i have a document and copy of that same document, are the indexes of the inline shape in the two documents guaranteed to be the same if one of those document is open but the other is not (i.e. does work do any shifting around internally of indices for instance)?


    Hi Mark

    The Index value of an InlineShape will be constant, assuming it's not moved or other InlineShapes added or deleted "above" it in the text.

    an InlineShape is treated the same as any text character in the document.


    Cindy Meister, VSTO/Word MVP
    Tuesday, November 9, 2010 5:14 PM