Free Spire.Presentation for .NET 3.3 (社区版)
Visual Studio
安装该类库后,注意在项目程序中添加引用Spire.Presentaion.dll,dll文件可在安装路径下的Bin文件夹中获取。
步骤 1 :添加using指令using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;
步骤 2 :创建文档 //创建Presentation类对象 Presentation presentation = new Presentation();
步骤 3 :绘制图形,并添加文本,设置文本自适应//绘制图形1IAutoShape textShape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 250, 300));//填充图形颜色textShape1.Fill.FillType = FillFormatType.Solid;textShape1.Fill.SolidColor.Color = Color.LightPink;textShape1.ShapeStyle.LineColor.Color = Color.White;//添加文本到到形状textShape1.TextFrame.Text = 'If the day is done , If birds sing no more .'+ 'If the wind has fiagged tired , Then draw the veil of darkness thick upon me ,'+ 'Even as thou hast wrapt the earth with The coverlet of sleep and tenderly closed ,' ; //设置文本自适应类型为NormaltextShape1.TextFrame.AutofitType = TextAutofitType.Normal;
步骤 4 :绘制图形2,添加文本,并设置自适应 //绘制形状2IAutoShape textShape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Ellipse, new RectangleF(350, 100, 200, 200));textShape2.Fill.FillType = FillFormatType.Solid;textShape2.Fill.SolidColor.Color = Color.LightGreen;textShape2.ShapeStyle.LineColor.Color = Color.White; //添加文本到图形textShape2.TextFrame.Text = 'Whose garment is torn and dust-laden ,Whose strength is exhausted,remove shame and poverty ,' + 'And renew his life like a flower under';//设置文本自适应类型为ShapetextShape2.TextFrame.AutofitType = TextAutofitType.Shape;
步骤 5 :保存文档presentation.SaveToFile('output.pptx', FileFormat.Pptx2010);System.Diagnostics.Process.Start('output.pptx');
完成代码步骤后,调试运行程序,生成文档,如下: