本篇文章将详细介绍如何使用spire.presentation来程序化地创建文本框并设置其形状格式, 包括线条,填充以及阴影等。
代码如下:
c#
//新建一个powerpoint文档并获取第一个幻灯片
presentation presentation = new presentation();
islide slide = presentation.slides[0];
//添加一个文本框(shape)到第一张幻灯片并添加文字。
iautoshape shape = slide.shapes.appendshape(shapetype.rectangle, new rectanglef(80, 120, 600, 200));
string textstring = "spire.presentation for .net 是一款专业的 powerpoint® 组件"
"使用该组件,开发者可以在 .net 平台上对 powerpoint® 文档"
"进行生成、读取、写入、修改、转换和打印等操作。"
"作为一个独立的控件,spire.presentation for .net "
"的运行无需要安装 microsoft powerpoint。";
shape.appendtextframe(textstring);
//设置shape线条颜色和宽度
shape.line.filltype = fillformattype.solid;
shape.line.width = 3;
shape.line.solidfillcolor.color = color.lightyellow;
//设置shape填充颜色为渐变色
shape.fill.filltype = spire.presentation.drawing.fillformattype.gradient;
shape.fill.gradient.gradientshape = spire.presentation.drawing.gradientshapetype.linear;
shape.fill.gradient.gradientstops.append(1f, knowncolors.skyblue);
shape.fill.gradient.gradientstops.append(0, knowncolors.lightpink);
//设置shape阴影
spire.presentation.drawing.outershadoweffect shadow = new spire.presentation.drawing.outershadoweffect();
shadow.blurradius = 20;
shadow.direction = 30;
shadow.distance = 8;
shadow.colorformat.color = color.lightgray;
shape.effectdag.outershadoweffect = shadow;
//设置shape向左旋转10度, 向右旋转为正
shape.rotation = -10;
//保存并打开文档
presentation.savetofile("结果文档.pptx", fileformat.pptx2007);
system.diagnostics.process.start("结果文档.pptx");
vb.net
'新建一个powerpoint文档并获取第一个幻灯片
dim presentation as new presentation()
dim slide as islide = presentation.slides(0)
'添加一个文本框(shape)到第一张幻灯片并添加文字。
dim shape as iautoshape = slide.shapes.appendshape(shapetype.rectangle, new rectanglef(80, 120, 600, 200))
dim textstring as string = "spire.presentation for .net 是一款专业的 powerpoint® 组件" "使用该组件,开发者可以在 .net 平台上对 powerpoint® 文档" "进行生成、读取、写入、修改、转换和打印等操作。" "作为一个独立的控件,spire.presentation for .net " "的运行无需要安装 microsoft powerpoint。"
shape.appendtextframe(textstring)
'设置shape线条颜色和宽度
shape.line.filltype = fillformattype.solid
shape.line.width = 3
shape.line.solidfillcolor.color = color.lightyellow
'设置shape填充颜色为渐变色
shape.fill.filltype = spire.presentation.drawing.fillformattype.gradient
shape.fill.gradient.gradientshape = spire.presentation.drawing.gradientshapetype.linear
shape.fill.gradient.gradientstops.append(1f, knowncolors.skyblue)
shape.fill.gradient.gradientstops.append(0, knowncolors.lightpink)
'设置shape阴影
dim shadow as new spire.presentation.drawing.outershadoweffect()
shadow.blurradius = 20
shadow.direction = 30
shadow.distance = 8
shadow.colorformat.color = color.lightgray
shape.effectdag.outershadoweffect = shadow
'设置shape向左旋转10度, 向右旋转为正
shape.rotation = -10
'保存并打开文档
presentation.savetofile("结果文档.pptx", fileformat.pptx2007)
system.diagnostics.process.start("结果文档.pptx")
效果图如下: