小編給大家分享一下C# PowerPoint中如何添加、修改和刪除動(dòng)畫,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)公司主營(yíng)息烽網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP開發(fā),息烽h5成都小程序開發(fā)搭建,息烽網(wǎng)站營(yíng)銷推廣歡迎息烽等地區(qū)企業(yè)咨詢為了讓PowerPoint文檔更加精美,在制作文檔的過程中,我們通常會(huì)給PowerPoint文檔中的元素如形狀、圖片、表格等添加動(dòng)畫。本文將介紹如何使用.NET PowerPoint組件Spire.Presentation和C#編程的方式給PowerPoint中的形狀添加動(dòng)畫,并修改和刪除現(xiàn)有動(dòng)畫。
在開始前我們可以了解一下PowerPoint中的動(dòng)畫。在PowerPoint中,動(dòng)畫大致可分為以下四大類:
1. 進(jìn)入
2. 強(qiáng)調(diào)
3. 退出
4. 動(dòng)作路徑
其中進(jìn)入、強(qiáng)調(diào)和退出類型下有多種不同的預(yù)設(shè)動(dòng)畫效果,有些動(dòng)畫效果還可以添加子效果,例如“進(jìn)入”分類下的“隨機(jī)線條”動(dòng)畫效果,可以設(shè)置水平方向或垂直方向子效果(默認(rèn)為水平方向)。下圖展示了如何在PowerPoint中添加動(dòng)畫:
如何在Spire.Presentation中添加動(dòng)畫
Spire.Presentation支持約151種動(dòng)畫效果(可以在AnimationEffectType枚舉中查看),這些動(dòng)畫效果及其所屬分類和子效果,請(qǐng)參見文末附表。
在使用以下代碼前,需要下載Spire.Presentation安裝, 并從安裝路徑下引用Spire.Presentation.dll到工程中(或可從NuGet搜索Spire.Presentation并安裝)。
添加動(dòng)畫
//加載文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("Input.pptx"); //獲取第一張幻燈片 ISlide slide = ppt.Slides[0]; RectangleF rect = new RectangleF(50, 200, 200, 200); //添加形狀到幻燈片 IShape cubeShape = slide.Shapes.AppendShape(ShapeType.Cube, rect); //給形狀添加動(dòng)畫效果 AnimationEffectCollection sequence = slide.Timeline.MainSequence; AnimationEffect effect = sequence.AddEffect(cubeShape, AnimationEffectType.Bounce); //保存文檔 ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013);
通常我們添加的動(dòng)畫效果默認(rèn)是“進(jìn)入”效果,下面的代碼將介紹如何添加“退出”動(dòng)畫效果:
//加載文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("Input.pptx"); //獲取第一張幻燈片 ISlide slide = ppt.Slides[0]; RectangleF rect = new RectangleF(50, 200, 200, 200); //添加形狀到幻燈片 IShape cubeShape = slide.Shapes.AppendShape(ShapeType.Cube, rect); //給形狀添加動(dòng)畫效果 AnimationEffectCollection sequence = slide.Timeline.MainSequence; AnimationEffect effect = sequence.AddEffect(cubeShape, AnimationEffectType.RandomBars); //將動(dòng)畫效果從默認(rèn)的“進(jìn)入”效果改為“退出”效果 effect.PresetClassType = TimeNodePresetClassType.Exit; //給該動(dòng)畫添加子效果 effect.Subtype = AnimationEffectSubtype.Vertical; //保存文檔 ppt.SaveToFile("ExitAnimationEffect.pptx", FileFormat.Pptx2013);
修改動(dòng)畫
對(duì)文檔中的現(xiàn)有動(dòng)畫,我們可以對(duì)其進(jìn)行修改。下面的代碼將介紹如何修改現(xiàn)有動(dòng)畫的類型和持續(xù)時(shí)間。
修改動(dòng)畫類型
//加載文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("Output.pptx"); //獲取第一張幻燈片 ISlide slide = ppt.Slides[0]; //修改第一個(gè)動(dòng)畫的類型 AnimationEffectCollection sequence = slide.Timeline.MainSequence; sequence[0].AnimationEffectType = AnimationEffectType.GrowAndTurn; //保存文本 ppt.SaveToFile("EditAnimationType.pptx", FileFormat.Pptx2013);
修改持續(xù)時(shí)間
//加載文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("Output.pptx"); //獲取第一張幻燈片 ISlide slide = ppt.Slides[0]; //修改第一個(gè)動(dòng)畫的持續(xù)時(shí)間 AnimationEffectCollection sequence = slide.Timeline.MainSequence; sequence[0].Timing.Duration = 5; //保存文檔 ppt.SaveToFile("EditAnimationTime.pptx", FileFormat.Pptx2013);
刪除動(dòng)畫
//加載文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("Output.pptx"); //獲取第一張幻燈片 ISlide slide = ppt.Slides[0]; //刪除第一個(gè)動(dòng)畫 AnimationEffectCollection sequence = slide.Timeline.MainSequence; sequence.RemoveAt(0); //保存文檔 ppt.SaveToFile("RemoveAnimation.pptx", FileFormat.Pptx2013);
附表(Spire.Presentation中動(dòng)畫效果及其所屬分類和子效果):
動(dòng)畫效果 | 分類 | 子效果 |
Appear | Entrance or Exit | EffectSubtype.None |
CurveUpDown | Entrance or Exit | EffectSubtype.None |
Ascend | Entrance or Exit | EffectSubtype.None |
Blast | Emphasis | EffectSubtype.None |
Blinds | Entrance or Exit | · EffectSubtype.Horizontal · EffectSubtype.Vertical |
Blink | Emphasis | EffectSubtype.None |
BoldFlash | Emphasis | EffectSubtype.None |
BoldReveal | Emphasis | EffectSubtype.None |
Boomerang | Entrance or Exit | EffectSubtype.None |
Bounce | Entrance or Exit | EffectSubtype.None |
Box | Entrance or Exit | · EffectSubtype.In · EffectSubtype.Out |
BrushOnColor | Emphasis | EffectSubtype.None |
BrushOnUnderline | Emphasis | EffectSubtype.None |
CenterRevolve | Entrance or Exit | EffectSubtype.None |
ChangeFillColor | Emphasis | · EffectSubtype.Instant · EffectSubtype.Gradual · EffectSubtype.GradualAndCycleClockwise · EffectSubtype.GradualAndCycleCounterClockwise |
ChangeFont | Emphasis | · EffectSubtype.Instant · EffectSubtype.Gradual |
ChangeFontColor | Emphasis | · EffectSubtype.Instant · EffectSubtype.Gradual · EffectSubtype.GradualAndCycleClockwise · EffectSubtype.GradualAndCycleCounterClockwise |
ChangeFontSize | Emphasis | · EffectSubtype.Instant · EffectSubtype.Gradual |
ChangeFontStyle | Emphasis | · EffectSubtype.FontBold · EffectSubtype.FontItalic · EffectSubtype.FontUnderline |
ChangeLineColor | Emphasis | · EffectSubtype.Instant · EffectSubtype.Gradual · EffectSubtype.GradualAndCycleClockwise · EffectSubtype.GradualAndCycleCounterClockwise |
Checkerboard | Entrance or Exit | · EffectSubtype.Vertical · EffectSubtype.Across |
Circle | Entrance or Exit | · EffectSubtype.In · EffectSubtype.Out |
ColorBlend | Emphasis | EffectSubtype.None |
ColorTypewriter | Entrance or Exit | EffectSubtype.None |
ColorWave | Emphasis | EffectSubtype.None |
ComplementaryColor | Emphasis | EffectSubtype.None |
ComplementaryColor2 | Emphasis | EffectSubtype.None |
Compress | Entrance or Exit | EffectSubtype.None |
ContrastingColor | Emphasis | EffectSubtype.None |
Crawl | Entrance or Exit | · EffectSubtype.Right · EffectSubtype.Left · EffectSubtype.Top · EffectSubtype.Bottom |
Credits | Entrance or Exit | EffectSubtype.None |
Custom | - | - |
Darken | Emphasis | EffectSubtype.None |
Desaturate | Emphasis | EffectSubtype.None |
Descend | Entrance or Exit | EffectSubtype.None |
Diamond | Entrance or Exit | · EffectSubtype.In · EffectSubtype.Out |
Dissolve | Entrance or Exit | EffectSubtype.None |
EaseInOut | Entrance or Exit | EffectSubtype.None |
Expand | Entrance or Exit | EffectSubtype.None |
Fade | Entrance or Exit | EffectSubtype.None |
FadedSwivel | Entrance or Exit | EffectSubtype.None |
FadedZoom | Entrance or Exit | · EffectSubtype.None · EffectSubtype.Center |
FlashBulb | Emphasis | EffectSubtype.None |
FlashOnce | Entrance or Exit | EffectSubtype.None |
Flicker | Emphasis | EffectSubtype.None |
Flip | Entrance or Exit | EffectSubtype.None |
Float | Entrance or Exit | EffectSubtype.None |
Fly | Entrance or Exit | · EffectSubtype.Right · EffectSubtype.Left · EffectSubtype.Top · EffectSubtype.Bottom · EffectSubtype.TopLeft · EffectSubtype.TopRight · EffectSubtype.BottomLeft · EffectSubtype.BottomRight |
Fold | Entrance or Exit | EffectSubtype.None |
Glide | Entrance or Exit | EffectSubtype.None |
GrowAndTurn | Entrance or Exit | EffectSubtype.None |
GrowShrink | Emphasis | EffectSubtype.None |
GrowWithColor | Emphasis | EffectSubtype.None |
Lighten | Emphasis | EffectSubtype.None |
LightSpeed | Entrance or Exit | EffectSubtype.None |
Path5PointStar | Path | EffectSubtype.None |
Path6PointStar | Path | EffectSubtype.None |
Path7PointStar | Path | EffectSubtype.None |
Path8PointStar | Path | EffectSubtype.None |
PathArcDown | Path | EffectSubtype.None |
PathArcLeft | Path | EffectSubtype.None |
PathArcRight | Path | EffectSubtype.None |
PathArcUp | Path | EffectSubtype.None |
PathBean | Path | EffectSubtype.None |
PathBounceLeft | Path | EffectSubtype.None |
PathBounceRight | Path | EffectSubtype.None |
PathBuzzsaw | Path | EffectSubtype.None |
PathCircle | Path | EffectSubtype.None |
PathCrescentMoon | Path | EffectSubtype.None |
PathCurvedSquare | Path | EffectSubtype.None |
PathCurvedX | Path | EffectSubtype.None |
PathCurvyLeft | Path | EffectSubtype.None |
PathCurvyRight | Path | EffectSubtype.None |
PathCurvyStar | Path | EffectSubtype.None |
PathDecayingWave | Path | EffectSubtype.None |
PathDiagonalDownRight | Path | EffectSubtype.None |
PathDiagonalUpRight | Path | EffectSubtype.None |
PathDiamond | Path | EffectSubtype.None |
PathDown | Path | EffectSubtype.None |
PathEqualTriangle | Path | EffectSubtype.None |
PathFigure8Four | Path | EffectSubtype.None |
PathFootball | Path | EffectSubtype.None |
PathFunnel | Path | EffectSubtype.None |
PathHeart | Path | EffectSubtype.None |
PathHeartbeat | Path | EffectSubtype.None |
PathHexagon | Path | EffectSubtype.None |
PathHorizontalFigure8 | Path | EffectSubtype.None |
PathInvertedSquare | Path | EffectSubtype.None |
PathInvertedTriangle | Path | EffectSubtype.None |
PathLeft | Path | EffectSubtype.None |
PathLoopdeLoop | Path | EffectSubtype.None |
PathNeutron | Path | EffectSubtype.None |
PathOctagon | Path | EffectSubtype.None |
PathParallelogram | Path | EffectSubtype.None |
PathPeanut | Path | EffectSubtype.None |
PathPentagon | Path | EffectSubtype.None |
PathPlus | Path | EffectSubtype.None |
PathPointyStar | Path | EffectSubtype.None |
PathRight | Path | EffectSubtype.None |
PathRightTriangle | Path | EffectSubtype.None |
PathSCurve1 | Path | EffectSubtype.None |
PathSCurve2 | Path | EffectSubtype.None |
PathSineWave | Path | EffectSubtype.None |
PathSpiralLeft | Path | EffectSubtype.None |
PathSpiralRight | Path | EffectSubtype.None |
PathSpring | Path | EffectSubtype.None |
PathSquare | Path | EffectSubtype.None |
PathStairsDown | Path | EffectSubtype.None |
PathSwoosh | Path | EffectSubtype.None |
PathTeardrop | Path | EffectSubtype.None |
PathTrapezoid | Path | EffectSubtype.None |
PathTurnDown | Path | EffectSubtype.None |
PathTurnRight | Path | EffectSubtype.None |
PathTurnUp | Path | EffectSubtype.None |
PathTurnUpRight | Path | EffectSubtype.None |
PathUp | Path | EffectSubtype.None |
PathUser | Path | EffectSubtype.None |
PathVerticalFigure8 | Path | EffectSubtype.None |
PathWave | Path | EffectSubtype.None |
PathZigzag | Path | EffectSubtype.None |
Peek | Entrance or Exit | · EffectSubtype.Bottom · EffectSubtype.Left · EffectSubtype.Right · EffectSubtype.Top |
Pinwheel | Entrance or Exit | EffectSubtype.None |
Plus | Entrance or Exit | · EffectSubtype.In · EffectSubtype.Out |
RandomBars | Entrance or Exit | · EffectSubtype.Horizontal · EffectSubtype.Vertical |
RandomEffects | Entrance or Exit | EffectSubtype.None |
RiseUp | Entrance | EffectSubtype.None |
Shimmer | Emphasis | EffectSubtype.None |
Sling | Entrance or Exit | EffectSubtype.None |
Spin | Emphasis | EffectSubtype.None |
Spinner | Emphasis | EffectSubtype.None |
Spiral | Entrance or Exit | EffectSubtype.None |
Split | Entrance or Exit | · EffectSubtype.HorizontalIn · EffectSubtype.HorizontalOut · EffectSubtype.VerticalIn · EffectSubtype.VerticalOut |
Stretch | Entrance or Exit | · EffectSubtype.Right · EffectSubtype.Left · EffectSubtype.Top · EffectSubtype.Bottom · EffectSubtype.Across |
Strips | Entrance or Exit | · EffectSubtype.UpLeft · EffectSubtype.UpRight · EffectSubtype.DownLeft · EffectSubtype.DownRight |
StyleEmphasis | Emphasis | EffectSubtype.None |
Swish | Entrance or Exit | EffectSubtype.None |
Swivel | Entrance or Exit | · EffectSubtype.Horizontal · EffectSubtype.Vertical |
Teeter | Emphasis | EffectSubtype.None |
Thread | Emphasis | EffectSubtype.None |
Transparency | Emphasis | EffectSubtype.None |
Unfold | Entrance or Exit | EffectSubtype.None |
VerticalGrow | Emphasis | EffectSubtype.None |
Wave | Emphasis | EffectSubtype.None |
Wedge | Entrance or Exit | EffectSubtype.None |
Wheel | Entrance or Exit | · EffectSubtype.Wheel1 · EffectSubtype.Wheel2 · EffectSubtype.Wheel3 · EffectSubtype.Wheel4 · EffectSubtype.Wheel8 |
Whip | Entrance or Exit | EffectSubtype.None |
Wipe | Entrance or Exit | · EffectSubtype.Top · EffectSubtype.Right · EffectSubtype.Bottom · EffectSubtype.Left |
Magnify | Entrance or Exit | EffectSubtype.None |
Zoom | Entrance or Exit | · EffectSubtype.In · EffectSubtype.Out · EffectSubtype.InCenter - only for Entrance type · EffectSubtype.OutBottom - only for Entrance type · EffectSubtype.OutSlightly · EffectSubtype.InSlightly · EffectSubtype.OutCenter - only for Exit type · EffectSubtype.InBottom - only for Exit type |
注:Entrance表示“進(jìn)入”, Exit表示“退出”,Emphasis表示“強(qiáng)調(diào)”,Path表示“動(dòng)作路徑”;EffectSubtype.None表示該效果無子效果。
以上是“C# PowerPoint中如何添加、修改和刪除動(dòng)畫”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。