概述
在文本框中我们可以实现的操作有很多,如插入文字、图片、设置字体大小、颜色、文本框背景填充、边框设置等。下面的示例中,将介绍通过C# 在PPT幻灯片中插入幻灯片的方法。
示例中包含了以下要点:
- 插入文本到文本框
- 设置边框颜色、粗细
- 文本框背景色填充
- 设置文本框旋转
- 设置文本框阴影效果
使用工具:Free Spire.Presentation for .NET 3.3(免费版)
注:安装后,注意在程序中添加引用Spire.Presentaton.dll(dll可在安装路径下的Bin文件夹中获取)
C# 代码(供参考)
步骤 1 :初始化Presentation类,加载测试文档
Presentation presentation = new Presentation(); presentation.LoadFromFile(@H_404_51@"@H_404[email protected]@H_404_51@");
ISlide slide = presentation.Slides[0];
步骤 3 :添加指定大小的文本框(shape)到幻灯片,并写入文本
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle,new RectangleF(@H_404_51@80,@H_404_51@50,1)">420,1)">350)); string textString = @H_404_51@万有引力的发现,是17世纪自然科学最伟大的成果之一。@H_404_51@" + @H_404_51@它把地面上的物体运动的规律和天体运动的规律统一了起来,对以后物理学和天文学的发展具有深远的影响。@H_404_51@它第一次揭示了自然界中一种基本相互作用的规律,在人类认识自然的历史上树立了一座里程碑。@H_404_51@牛顿的万有引力概念是所有科学中最实用的概念之一。牛顿认为万有引力是所有物质的基本特征,这成为大部分物理科学的理论基石。@H_404_51@"; shape.AppendTextFrame(textString);
步骤 4 :设置文本框边框样式、填充样式、阴影效果、旋转度等
//设置shape线条颜色和宽度 shape.Line.FillType = FillFormatType.solid; shape.Line.Width = @H_404_51@2; shape.Line.solidFillColor.Color = Color.White; 设置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.LightGray); shape.Fill.Gradient.GradientStops.Append(@H_404_51@0,KNownColors.LightBlue); 设置shape阴影 Spire.Presentation.Drawing.OuterShadowEffect shadow = Spire.Presentation.Drawing.OuterShadowEffect(); shadow.BlurRadius = @H_404_51@20; shadow.Direction = @H_404_51@30; shadow.distance = @H_404_51@8; shadow.ColorFormat.Color = Color.LightGray; shape.EffectDag.OuterShadowEffect = shadow; 设置shape向右旋转5度(向左旋转设置数值为负即可) shape.Rotation = @H_404_51@5;
步骤 5 :保存文档
presentation.SavetoFile(@H_404[email protected]@H_404_51@",FileFormat.Pptx2010);
全部代码:
using Spire.Presentation; Spire.Presentation.Drawing; System.Drawing; namespace InsertTextBox_PPT { class Program { static void Main(string[] args) { 实例化Presentation类对象,加载文档并获取第一个幻灯片 Presentation presentation = Presentation(); presentation.LoadFromFile(@H_404_51@); ISlide slide = presentation.Slides[@H_404_51@]; 添加一个文本框(shape)到第一张幻灯片并添加文字。 IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle,1)">)); " + @H_404_51@; shape.AppendTextFrame(textString); 设置shape线条颜色和宽度 shape.Line.FillType = FillFormatType.solid; shape.Line.Width = @H_404_51@; shape.Line.solidFillColor.Color = Color.White; 设置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.LightGray); shape.Fill.Gradient.GradientStops.Append(NownColors.LightBlue); 设置shape阴影 Spire.Presentation.Drawing.OuterShadowEffect shadow = Spire.Presentation.Drawing.OuterShadowEffect(); shadow.BlurRadius = @H_404_51@; shadow.Direction = @H_404_51@; shadow.distance = @H_404_51@; shadow.ColorFormat.Color = Color.LightGray; shape.EffectDag.OuterShadowEffect = shadow; 设置shape向右旋转5度(向左旋转设置数值为负即可) shape.Rotation = @H_404_51@5; 保存并打开文档 presentation.SavetoFile(stem.Diagnostics.Process.Start(@H_404_51@); } } }
(本文完)
转载请注明出处!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。