前面我们介绍了spire.presentation 添加和删除常规图形 , 下文将详细介绍如何使用spire.presentation 操作幻灯片中的图形,包括旋转图形,重置图形的大小和位置,以及重新排列重叠图形的顺序。
旋转图形
c#
//创建一个powerpoint文档并加载示例文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//获取第一个幻灯片里的第一个图形
ishape shape = ppt.slides[0].shapes[0];
//旋转180度
shape.rotation = 180;
//保存文档
ppt.savetofile("rotate.pptx", fileformat.pptx2010);
vb.net
'创建一个powerpoint文档并加载示例文档
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'获取第一个幻灯片里的第一个图形
dim shape as ishape = ppt.slides(0).shapes(0)
'旋转180度
shape.rotation = 180
'保存文档
ppt.savetofile("rotate.pptx", fileformat.pptx2010)
重置图形的大小和位置
c#
//创建一个powerpoint文档并加载示例文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//获取原始幻灯片高度和宽度
float currentheight = ppt.slidesize.size.height;
float currentwidth = ppt.slidesize.size.width;
//将幻灯片大小设置为a3.
ppt.slidesize.type = slidesizetype.a3;
//获取新幻灯片的高度和宽度
float newheight = ppt.slidesize.size.height;
float newwidth = ppt.slidesize.size.width;
//指定高度和宽度的比例
float ratioheight = newheight / currentheight;
float ratiowidth = newwidth / currentwidth;
//重新设置图形大小和位置
foreach (islide slide in ppt.slides)
{
foreach (ishape shape in slide.shapes)
{
//重置图形大小
shape.height = shape.height * ratioheight;
shape.width = shape.width * ratiowidth;
//重置图形位置
shape.left = shape.left * ratioheight;
shape.top = shape.top * ratiowidth;
}
//保存文档
ppt.savetofile("resetsizeposition.pptx", fileformat.pptx2010);
}
vb.net
'创建一个powerpoint文档并加载示例文档
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'获取原始幻灯片高度和宽度
dim currentheight as single = ppt.slidesize.size.height
dim currentwidth as single = ppt.slidesize.size.width
'将幻灯片大小设置为a3.
ppt.slidesize.type = slidesizetype.a3
'获取新幻灯片的高度和宽度
dim newheight as single = ppt.slidesize.size.height
dim newwidth as single = ppt.slidesize.size.width
'指定高度和宽度的比例
dim ratioheight as single = newheight / currentheight
dim ratiowidth as single = newwidth / currentwidth
'重新设置图形大小和位置
for each slide as islide in ppt.slides
for each shape as ishape in slide.shapes
'重置图形大小
shape.height = shape.height * ratioheight
shape.width = shape.width * ratiowidth
'重置图形位置
shape.left = shape.left * ratioheight
shape.top = shape.top * ratiowidth
next
'保存文档
ppt.savetofile("resetsizeposition.pptx", fileformat.pptx2010)
next
重新排列重叠图形的顺序
c#
//创建一个powerpoint文档并加载示例文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//获取第二个幻灯片里的第一个图形
ishape shape = ppt.slides[1].shapes[0];
//重新设置图形的顺序.
ppt.slides[1].shapes.zorder(1, shape);
//保存文档
ppt.savetofile("reorder.pptx", fileformat.pptx2010);
vb.net
'创建一个powerpoint文档并加载示例文档
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'获取第二个幻灯片里的第一个图形
dim shape as ishape = ppt.slides(1).shapes(0)
'重新设置图形的顺序.
ppt.slides(1).shapes.zorder(1, shape)
'保存文档
ppt.savetofile("reorder.pptx", fileformat.pptx2010)