- using Spire.Presentation;
- using Spire.Presentation.Drawing;
- using System.Drawing;
- namespace InsertTextbox_PPT
- {
- class Program
- {
- static void Main(string[] args)
- {
- //实例化Presentation类对象,加载文档并获取第一个幻灯片
- Presentation presentation = new Presentation();
- presentation.LoadFromFile("test.pptx");
- ISlide slide = presentation.Slides[0];
- //添加一个文本框(shape)到第一张幻灯片并添加文字。
- IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(80, 50, 420, 350));
- string textString = "万有引力的发现,是17世纪自然科学最伟大的成果之一。" +
- "它把地面上的物体运动的规律和天体运动的规律统一了起来,对以后物理学和天文学的发展具有深远的影响。" +
- "它第一次揭示了自然界中一种基本相互作用的规律,在人类认识自然的历史上树立了一座里程碑。" +
- "牛顿的万有引力概念是所有科学中最实用的概念之一。牛顿认为万有引力是所有物质的基本特征,这成为大部分物理科学的理论基石。";
- shape.AppendTextFrame(textString);
- //设置shape线条颜色和宽度
- shape.Line.FillType = FillFormatType.Solid;
- shape.Line.Width = 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(0, KnownColors.LightBlue);
- //设置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向右旋转5度(向左旋转设置数值为负即可)
- shape.Rotation = 5;
- //保存并打开文档
- presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
- System.Diagnostics.Process.Start("result.pptx");
- }
- }
- }