Paul FosterMy first attempt to post was with IE 8 and it didn't take the content from the editor :(
So, reposting in Firefox:
Platfom is VS 2010 / Microsoft Word 2007
General use case is parsing TextBoxes out of a Word document, assembling them into groups for copying/exporting.
I have a document with TextBox Shape objects that all have absolute positions, with most Relative to the Page, but I have a couple of TextBoxes with positions such as "-0.1" to the right of the "Column" and "2.0" below the "Paragraph". I need to compare positions of all the TextBoxes on the page, so I need them all with Page-relative abosolute positions. I can't seem to find an API that tells me:
1. What the Shape.Top & Shape.Left properties are relative to.
2. How to get the page-relative position of the object it's relative to.
If it makes any difference - I'm testing using a stand alone console app, just using the Interop libraries to talk to word. I'm not running as an Add-in.
- 已编辑 pfoster 2012年3月28日 23:20
Thanks for posting in the MSDN Forum.
It's based on my experience the properties which your mentioned are measured via point (72 points = 1 inch).
I hope it can help you.
Have a good day,
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
My question wasn't related to the units that the property is in. I am aware they're in points. Let me clarify:
I have the values circled in Green, what I need to know is the property values circled in yellow.
I've partially answered my own question, but raised some more related to the same issue.
I see the following properties:
Microsoft.Office.Interop.Word.Shape.WrapFormat.Type - tells the type of wrap (from the second page of the properties dialog above)
Microsoft.Office.Interop.Word.Shape.RelativeHorizontalPosition - An enum value indicating the value of the "to the right of". Values are Character, Column, Page, others ...
But I'm still confused by the fact that these three different ways to get the position are giving me three different results:
Shape shape; // Approach 1 int topRelative = shape.TopRelative; // Approach 2 int top = shape.Top; // Approach 3 shape.Select(); int topFromSelect = shape.Application.Selection.get_Information(Word.WdInformation.wdHorizontalPositionRelativeToPage);
For example, here's a Shape with properties:
- Type: msoPicture
- RelativeVerticalPosition: wdRelativeVerticalPositionPage
- WrapFormat.Type: wdWrapBehind
- Top (Approach 1): -0.5
- TopRelative (Approach 2): -999999
- (Approach 3): 205.15
- RelativeHorizontalPosition: wdRelativeHorizontalPositionPage
- Left (Approach 1): -0.5
- LeftRelative (Approach 2): -999999
- (Approach 3): 18.15
- Width: 613
- Height: 793
It should be noted also that these shapes were created by automated software, not necessarily a human using Word.
What's the explanation as to why the values are different, even when the Relative*Position properties all say *Page?
This applies to the duplicate thread you entered in the "Word for Developers" Forum. Thank you for your patience in both Forum threads. The list of content, and the remarks for several address your question for why you see three different values for the position of the shape. The most telling is that the position of a shape is always related to the anchor point - which is briefly described in two of the topics listed.
Shape.TopRelative Property (Microsoft.Office.Interop.Word)
Shape.TopRelative Property (Word) - MSDN – Explore Windows, Web ...
Shape.RelativeHorizontalPosition Property (Microsoft.Office ...
Shape Properties (Microsoft.Office.Interop.Word)
See this statement in the following page “A shape is always attached to an anchoring range”:
Shape Object - MSDN – Explore Windows, Web, Cloud, and Windows ...
Shape.Anchor Property (Word) - MSDN – Explore Windows, Web ...
Please see the code examples in this page:
RelativeHorizontalPosition Property - MSDN – Explore Windows ...
Once again, thanks for your patience.
Senior Technical Support Lead
- 已标记为答案 pfoster 2012年4月13日 23:53