本文将介绍如何使用spire.presentation for .net取消powerpoint文档中的形状组合。
原powerpoint文档含有2个形状组合:
c#
using spire.presentation;
namespace ungroupshapes
{
class program
{
static void main(string[] args)
{
//创建presentation实例
presentation ppt = new presentation();
//加载powerpoint文档
ppt.loadfromfile("sample.pptx");
//获取第一张幻灯片
islide slide = ppt.slides[0];
//遍历幻灯片中的形状
for(int i = 0; i< slide.shapes.count;i )
{
ishape shape = slide.shapes[i];
//判断形状是否是组合形状
if (shape is groupshape)
{
groupshape groupshape = shape as groupshape;
//取消形状组合
slide.ungroup(groupshape);
}
}
//保存结果文档
ppt.savetofile("ungroupshapes.pptx", fileformat.pptx2013);
}
}
}
vb.net
imports spire.presentation
namespace ungroupshapes
class program
private shared sub main(byval args as string())
dim ppt as presentation = new presentation()
ppt.loadfromfile("sample.pptx")
dim slide as islide = ppt.slides(0)
for i as integer = 0 to slide.shapes.count - 1
dim shape as ishape = slide.shapes(i)
if typeof shape is groupshape then
dim groupshape as groupshape = trycast(shape, groupshape)
slide.ungroup(groupshape)
end if
next
ppt.savetofile("ungroupshapes.pptx", fileformat.pptx2013)
end sub
end class
end namespace
取消形状组合后的结果文档: