当您想在一个ppt中使用两种或两种以上的背景时,可以通过创建多个幻灯片母版来实现。在本文中,您将学习如何使用spire.presentation创建额外的幻灯片母版并将它们应用到不同的幻灯片。
c#
//新建ppt文档
presentation ppt = new presentation();
ppt.slidesize.type = slidesizetype.screen16x9;
//插入4页幻灯片(连同默认的幻灯片,文档中共5页)
for (int i = 0; i < 4; i )
{
ppt.slides.append();
}
//获取默认的母版
imasterslide first_master = ppt.masters[0];
//新建并获取第二个母板
ppt.masters.appendslide(first_master);
imasterslide second_master = ppt.masters[1];
//为两个母版分别设置不同的背景图片
string pic1 = @"c:\users\administrator\desktop\image-1.png";
string pic2 = @"c:\users\administrator\desktop\image-2.png";
rectanglef rect = new rectanglef(0, 0, ppt.slidesize.size.width, ppt.slidesize.size.height);
first_master.slidebackground.fill.filltype = fillformattype.picture;
iembedimage image1 = first_master.shapes.appendembedimage(shapetype.rectangle, pic1, rect);
first_master.slidebackground.fill.picturefill.picture.embedimage = image1 as iimagedata;
second_master.slidebackground.fill.filltype = fillformattype.picture;
iembedimage image2 = second_master.shapes.appendembedimage(shapetype.rectangle, pic2, rect);
second_master.slidebackground.fill.picturefill.picture.embedimage = image2 as iimagedata;
//在第一页应用第一个母版及版式(如果不希望出现板式,请选择板式6)
ppt.slides[0].layout = first_master.layouts[1];
//在剩下的幻灯片应用第二个母版及版式
for (int i = 1; i < ppt.slides.count; i )
{
ppt.slides[i].layout = second_master.layouts[8];
}
//保存文档
ppt.savetofile("result.pptx", fileformat.pptx2013);
vb.net
'新建ppt文档
dim ppt as new presentation()
ppt.slidesize.type = slidesizetype.screen16x9
'插入4页幻灯片(连同默认的幻灯片,文档中共5页)
for i as integer = 0 to 3
ppt.slides.append()
next
'获取默认的母版
dim first_master as imasterslide = ppt.masters(0)
'新建并获取第二个母板
ppt.masters.appendslide(first_master)
dim second_master as imasterslide = ppt.masters(1)
'为两个母版分别设置不同的背景图片
dim pic1 as string = "c:\users\administrator\desktop\image-1.png"
dim pic2 as string = "c:\users\administrator\desktop\image-2.png"
dim rect as new rectanglef(0, 0, ppt.slidesize.size.width, ppt.slidesize.size.height)
first_master.slidebackground.fill.filltype = fillformattype.picture
dim image1 as iembedimage = first_master.shapes.appendembedimage(shapetype.rectangle, pic1, rect)
first_master.slidebackground.fill.picturefill.picture.embedimage = trycast(image1, iimagedata)
second_master.slidebackground.fill.filltype = fillformattype.picture
dim image2 as iembedimage = second_master.shapes.appendembedimage(shapetype.rectangle, pic2, rect)
second_master.slidebackground.fill.picturefill.picture.embedimage = trycast(image2, iimagedata)
'在第一页应用第一个母版及版式(如果不希望出现板式,请选择板式6)
ppt.slides(0).layout = first_master.layouts(1)
'在剩下的幻灯片应用第二个母版及版式
for i as integer = 1 to ppt.slides.count - 1
ppt.slides(i).layout = second_master.layouts(8)
next
'保存文档
ppt.savetofile("result.pptx", fileformat.pptx2013)