none
Shapes with Open XML SDK RRS feed

  • Question

  • Hi Team Open XML.

    I started working on OOXML from past 1 month and I encountered so many good things about the SDK and its written beautifully. I would like to take this opportunity to thanks to OOXML Team.

    I have the following question for the day with respect to reading word documents using OOXML:

    1. Shapes from Microsoft Word (2007, 2010 or 2013) are DrawingML Objects as per spec, However there exists a Multiple Group tags for those objects when I view the document in Open XML SDK 2.5. This makes me hard to read those docs and decide what to do with those objects. What are the reasons for more than one Group objects in the Open XML API? When there is only one DrawingML Object? Also it co-exists with these group elements in that Run Tag.

    2. I am having hard time adding these VML objects and convert them to HTML to render into the UI. Therefore I want to know if there exists a way to get the exact location of these VML Objects in the word document? The moment I copy-paste these objects in the word document manually, the position of these objects are unknown. Later when I drag these shapes to some other location in the word document, SDK 2.5 does not read them at that position. What could be the reason?

    Please let me know

    Thanks,

    Triguna


    Wednesday, June 25, 2014 4:35 AM

Answers

  • Hi Triguna

    For (1) I recommend you ask in the forum that deals with the Open XML specification. They're most likely to have an answer as to "why". http://social.msdn.microsoft.com/Forums/en-US/home?forum=os_binaryfile

    (2) I'm not a graphics expert, in that I don't "know" VML and such. However, if we're talking about the way SHAPE objects behave in Word, then I believe I have enough background to try to describe what's going on...

    A SHAPE object is "anchored" to a specific position in the document text. It never "belongs" to a page, only to the text to which it is anchored. To help you envision this: If the anchoring text moves to a different page, the SHAPE will also move to that page, no matter where it appears on the original page: top, bottom, middle.

    Positioning of Shapes is very complex, but in a nutshell, the position can be relative to the Anchor or to the page (or a page element, such as a margin). It will still change pages with the Anchor, even if positioned relative to the page.

    When you used Shapes.Add you can specify a RANGE object which will act as the Anchor. This is the ONLY time code can influence the Anchor position directly. When a Shape is inserted by the user, generally the cursor position supplies the anchor (usually the first character in that paragraph).

    The user can DRAG the anchor to another position (paragraph). When the user drags a Shape, the anchor will move to the paragraph nearest to where the Shape has been "dropped". It is also possible to LOCK the anchor to its current position (Range). Locking the anchor does NOT prevent the Shape from being moved, only the anchor point will not change when the Shape is dragged.

    I believe this last bit explains what you're seeing...


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, June 25, 2014 3:19 PM
    Moderator

All replies

  • Hi Triguna

    For (1) I recommend you ask in the forum that deals with the Open XML specification. They're most likely to have an answer as to "why". http://social.msdn.microsoft.com/Forums/en-US/home?forum=os_binaryfile

    (2) I'm not a graphics expert, in that I don't "know" VML and such. However, if we're talking about the way SHAPE objects behave in Word, then I believe I have enough background to try to describe what's going on...

    A SHAPE object is "anchored" to a specific position in the document text. It never "belongs" to a page, only to the text to which it is anchored. To help you envision this: If the anchoring text moves to a different page, the SHAPE will also move to that page, no matter where it appears on the original page: top, bottom, middle.

    Positioning of Shapes is very complex, but in a nutshell, the position can be relative to the Anchor or to the page (or a page element, such as a margin). It will still change pages with the Anchor, even if positioned relative to the page.

    When you used Shapes.Add you can specify a RANGE object which will act as the Anchor. This is the ONLY time code can influence the Anchor position directly. When a Shape is inserted by the user, generally the cursor position supplies the anchor (usually the first character in that paragraph).

    The user can DRAG the anchor to another position (paragraph). When the user drags a Shape, the anchor will move to the paragraph nearest to where the Shape has been "dropped". It is also possible to LOCK the anchor to its current position (Range). Locking the anchor does NOT prevent the Shape from being moved, only the anchor point will not change when the Shape is dragged.

    I believe this last bit explains what you're seeing...


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, June 25, 2014 3:19 PM
    Moderator
  • Thanks Cindy. That throws me a lot of light on SHAPE objects and its behavior.

    OpenXMLSDK

    Friday, June 27, 2014 4:31 AM