Spire.Presentation是一款灵活的PPT控件,可以帮助开发人员在电脑上没有安装Microsoft PowerPoint软件的情况下对PPT各个版本的文档进行生成、读取、编辑和转换等操作,同样控件还提供了很多其他功能,如设置动画效果,开发人员使用Spire.presention可以在幻灯片中插入和设置动画,可以设置动画的图形、填充颜色、移动轨迹以及动画效果等,这篇文章主要介绍如何在PPT中设置动画效果,具体如下:
using Spire.Presentation;
using System.Drawing;
using Spire.Presentation.Drawing.Animation;
using Spire.Presentation.Drawing;
namespace SetAnimationsC
{
class Program
{
static void Main(string[] args)
{
//create PPT document
Presentation presentation = new Presentation();
//set background Image
string ImageFile = @" bg.png";
RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
//set the animation of slide to Circle
presentation.Slides[0].SlideShowTransition.Type = Spire.Presentation.Drawing.Transition.TransitionType.Circle;
//append new shape - Triangle
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Triangle, new RectangleF(100, 60, 100, 100));
//set the color of shape
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.Orange;
shape.ShapeStyle.LineColor.Color = Color.White;
//set the animation of shape
shape.Slide.Timeline.MainSequence.AddEffect(shape, AnimationEffectType.PathBounceRight);
//append new shape
shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 200, 600, 200));
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
//add text to shape
shape.AppendTextFrame("The sample demonstrates how to set Animations in PPT using Spire.Presentation.");
//add new paragraph
shape.TextFrame.Paragraphs.Append(new TextParagraph());
//add text to paragraph
shape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange("Spire.Office for .NET is a compilation of Enterprise-
Spire.DocViewer, and Spire.BarCode. Spire.Office contains the most up-to-date versions of the above .NET components."));
//set the Font
foreach (TextParagraph para in shape.TextFrame.Paragraphs)
{
para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
para.TextRanges[0].Fill.FillType = FillFormatType.Solid;
para.TextRanges[0].Fill.SolidColor.Color = Color.Black;
para.Alignment = TextAlignmentType.Left;
para.Indent = 35;
}
//save the document
presentation.SaveToFile("animations.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("animations.pptx");
}
}
}