powerpoint文档(幻灯片)是一种常见的演示文档,在演讲,教学,产品演示等方面得到广泛的应用。本文将介绍如何通过编程的方式创建powerpoint文档。
创建简单的powerpoint文档
c#
//新建一个powerpoint文档(默认包含一页空白幻灯片)
presentation ppt = new presentation();
//设置幻灯片大小和方向
ppt.slidesize.type = slidesizetype.screen16x9;
ppt.slidesize.orientation = slideorienation.landscape;
//为幻灯片设置背景图片
string imagefile = "background.jpg";
rectanglef rect = new rectanglef(0, 0, ppt.slidesize.size.width, ppt.slidesize.size.height);
ppt.slides[0].slidebackground.fill.filltype = fillformattype.picture;
iembedimage image = ppt.slides[0].shapes.appendembedimage(shapetype.rectangle, imagefile, rect);
ppt.slides[0].slidebackground.fill.picturefill.picture.embedimage = image as iimagedata;
//添加一个图形(shape)到第一张幻灯片
iautoshape textboxshape = ppt.slides[0].shapes.appendshape(shapetype.rectangle, new rectanglef(50, 70, 600, 100));
textboxshape.shapestyle.linecolor.color = color.transparent;
textboxshape.fill.filltype = spire.presentation.drawing.fillformattype.none;
//清除图形上的段落(默认有一个空白段落)
textboxshape.textframe.paragraphs.clear();
//在图形上添加段落及内容
textboxshape.textframe.paragraphs.append(new textparagraph());
textboxshape.textframe.paragraphs[0].textranges.append(new textrange("spire.presentation for .net"));
textboxshape.textframe.paragraphs[0].spaceafter = 50f;
//添加第二段及内容
textboxshape.textframe.paragraphs.append(new textparagraph());
string text = "一款专业的 powerpoint 组件,使用该组件,开发者可以在 .net 平台上对 powerpoint 文档进行生成、读取、写入、修改、"
"转换和打印等操作。 作为一个独立的控件,spire.presentation for .net 的运行无需要安装 microsoft powerpoint。";
textboxshape.textframe.paragraphs[1].textranges.append(new textrange(text));
//设置段落中文字的字体、大小、颜色及段落的对齐方式、段首缩进距离
foreach (textparagraph para in textboxshape.textframe.paragraphs)
{
para.textranges[0].latinfont = new textfont("arial rounded mt bold");
para.textranges[0].fontheight = 13f;
para.textranges[0].fill.filltype = fillformattype.solid;
para.textranges[0].fill.solidcolor.color = color.black;
para.alignment = textalignmenttype.left;
para.indent = 35;
}
//保存文档
ppt.savetofile("创建powerpoint.pptx", fileformat.pptx2013);
vb.net
'新建一个powerpoint文档(默认包含一页空白幻灯片)
dim ppt as new presentation()
'设置幻灯片大小和方向
ppt.slidesize.type = slidesizetype.screen16x9
ppt.slidesize.orientation = slideorienation.landscape
'为幻灯片设置背景图片
dim imagefile as string = "background.jpg"
dim rect as new rectanglef(0, 0, ppt.slidesize.size.width, ppt.slidesize.size.height)
ppt.slides(0).slidebackground.fill.filltype = fillformattype.picture
dim image as iembedimage = ppt.slides(0).shapes.appendembedimage(shapetype.rectangle, imagefile, rect)
ppt.slides(0).slidebackground.fill.picturefill.picture.embedimage = trycast(image, iimagedata)
'添加一个图形(shape)到第一张幻灯片
dim textboxshape as iautoshape = ppt.slides(0).shapes.appendshape(shapetype.rectangle, new rectanglef(50, 70, 600, 100))
textboxshape.shapestyle.linecolor.color = color.transparent
textboxshape.fill.filltype = spire.presentation.drawing.fillformattype.none
'清除图形上的段落(默认有一个空白段落)
textboxshape.textframe.paragraphs.clear()
'在图形上添加段落及内容
textboxshape.textframe.paragraphs.append(new textparagraph())
textboxshape.textframe.paragraphs(0).textranges.append(new textrange("spire.presentation for .net"))
textboxshape.textframe.paragraphs(0).spaceafter = 50f
'添加第二段及内容
textboxshape.textframe.paragraphs.append(new textparagraph())
dim text as string = "一款专业的 powerpoint 组件,使用该组件,开发者可以在 .net 平台上对 powerpoint 文档进行生成、读取、写入、修改、" "转换和打印等操作。 作为一个独立的控件,spire.presentation for .net 的运行无需要安装 microsoft powerpoint。"
textboxshape.textframe.paragraphs(1).textranges.append(new textrange(text))
'设置段落中文字的字体、大小、颜色及段落的对齐方式、段首缩进距离
for each para as textparagraph in textboxshape.textframe.paragraphs
para.textranges(0).latinfont = new textfont("arial rounded mt bold")
para.textranges(0).fontheight = 13f
para.textranges(0).fill.filltype = fillformattype.solid
para.textranges(0).fill.solidcolor.color = color.black
para.alignment = textalignmenttype.left
para.indent = 35
next
'保存文档
ppt.savetofile("创建powerpoint.pptx", fileformat.pptx2013)
设置文档属性
c#
//新建一个文档
presentation ppt= new presentation();
//通过documentproperty设置文档属性
ppt.documentproperty.application = "spire.presentation";
ppt.documentproperty.author = "http://www.e-iceblue.com/";
ppt.documentproperty.company = "冰蓝科技有限公司";
ppt.documentproperty.keywords = "c#,powerpoint文档属性";
ppt.documentproperty.comments = "无";
ppt.documentproperty.category = "powerpoint教程";
ppt.documentproperty.title = "如何为powerpoint文档添加属性";
ppt.documentproperty.subject = "add document properties in c#";
ppt.documentproperty.manager = "gary";
//保存文档
ppt.savetofile("设置文档属性.pptx", fileformat.pptx2013);
vb.net
'新建一个文档
dim ppt as new presentation()
'通过documentproperty设置文档属性
ppt.documentproperty.application = "spire.presentation"
ppt.documentproperty.author = "http://www.e-iceblue.com/"
ppt.documentproperty.company = "冰蓝科技有限公司"
ppt.documentproperty.keywords = "c#,powerpoint文档属性"
ppt.documentproperty.comments = "无"
ppt.documentproperty.category = "powerpoint教程"
ppt.documentproperty.title = "如何为powerpoint文档添加属性"
ppt.documentproperty.subject = "add document properties in c#"
ppt.documentproperty.manager = "gary"
'保存文档
ppt.savetofile("设置文档属性.pptx", fileformat.pptx2013)