如何使用Open xml sdk修改形状(图像,connectionShape等)宽度高度和位置?

时间:2015-01-15 12:50:29

标签: c# powerpoint openxml-sdk

我们可以使用 -

获得形状尺寸
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

我们还可以设置这些值吗?

1 个答案:

答案 0 :(得分:1)

是的,我们可以更改ShapeProperties并修改形状偏移和尺寸。 以下代码将形状缩小到50%。

shapeProp = shape.ShapeProperties;

        Int64Value prevWidth = shapeProp.Transform2D.Extents.Cx;
        Int64Value prevHeight = shapeProp.Transform2D.Extents.Cy;

        shapeProp.Transform2D.Extents.Cx = (shapeProp.Transform2D.Extents.Cx * 50) / 100;
        shapeProp.Transform2D.Extents.Cy = (shapeProp.Transform2D.Extents.Cy * 50) / 100;
        shapeProp.Transform2D.Offset.X += (prevWidth - shapeProp.Transform2D.Extents.Cx) / 2;
        shapeProp.Transform2D.Offset.Y += (prevHeight - shapeProp.Transform2D.Extents.Cy) / 2;