2012-11-29 81 views
3

我在玩OpenXmlSDK,看看它是否是我们Powerpoint需求的可行解决方案。有一件事需要的是在Powerpoint中定位形状的能力。我一直在寻找一种方法来获得Shape的位置,但只能遇到MSDN“如何”http://msdn.microsoft.com/en-us/library/cc850828.aspx和位置类(但没有办法从形状中获取它)http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.wordprocessing.position%28v=office.14%29.aspx如何在Powerpoint中获取形状的位置和尺寸?

我怎么做这样的事情:

PresentationDocument presentationDocument = PresentationDocument.Open("C:\\MyDoc.pptx", true); 
IdPartPair pp = presentationDocument.PresentationPart.SlideParts.First().Parts.FirstOrDefault(); 
var shape = pp.OpenXmlPart; 
// How do I get the position and dimensions? 

回答

1

通过XML有问题的幻灯片去找XFRM元素,它应该包含关闭(偏移量)和EXT(程度)子元素。测量值在动车组中(参见Wouter van Vugt文件的最后一页)。

2

您有形状的尺寸2个变量: - 胶印使您的外形 右上角的位置 - 区段给人的尺寸过你的形状

shape.ShapeProperties.Transform2D.Offset.X //gives the x position of top left corner 
shape.ShapeProperties.Transform2D.Offset.Y //gives the y position of top left corner 

shape.ShapeProperties.Transform2D.Extents.X //gives the x size of the shape : the width 
shape.ShapeProperties.Transform2D.Extents.Y //gives the y size of the shape : the height