多语言展示
当前在线:310今日阅读:176今日分享:34

C# 设置PPT幻灯片文字自适应效果

此条经验将介绍C#如何设置PPT幻灯片中文字的自适应效果。
工具/原料
1

Free Spire.Presentation for .NET 3.3 (社区版)

2

Visual Studio

dll引用

安装该类库后,注意在项目程序中添加引用Spire.Presentaion.dll,dll文件可在安装路径下的Bin文件夹中获取。

C# 代码示例(供参考)
1

步骤 1 :添加using指令using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;

2

步骤 2 :创建文档 //创建Presentation类对象 Presentation presentation = new Presentation();

3

步骤 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

步骤 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

步骤 5 :保存文档presentation.SaveToFile('output.pptx', FileFormat.Pptx2010);System.Diagnostics.Process.Start('output.pptx');

6

完成代码步骤后,调试运行程序,生成文档,如下:

推荐信息