最近想做一个小东西,打算将ppt和视频结合在一起。所以研究起了powerpoint。
首先,环境是vs2008,office我用的是2010(03的帮助文档在我电脑上不知道怎么回事打不开,07在我电脑上装不起,杯具)。
接下来,是如果调用PowerPoint,建一个c#的控制台应用程序,然后右键解决方案资源管理器里的引用-》添加引用-》浏览:找到office安装路径 下有个OFFICE14(ps 03的位office11),找到msppt.olb
例如D:\Program Files\Microsoft Office\Office14;找到后添加进去,引入框中便会多出几个接口Microsoft.Office.Interop.PowerPoint和Microsoft.Office.Core。然后在程序中添加引用。
程序列子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
namespace tst
{
class Program
{
static void Main(string[] args)
{
// Purpose: Creates a PowerPoint presentation,
// adds a slide and two shapes to the slide,
// animates the shapes, and runs the slide show.
Application ppApp = new Application();
// Create a new PowerPoint presentation.
Presentation objPres = ppApp.Presentations.Add(MsoTriState.msoTrue);
// Add a slide to the presentation.
_Slide objSlide = objPres.Slides.Add
(1, PpSlideLayout.ppLayoutBlank);
// Place two shapes on the slide.
Microsoft.Office.Interop.PowerPoint.Shape objSquareShape = objSlide.Shapes.AddShape
(MsoAutoShapeType.msoShapeRectangle,
0, 0, 100, 100);
Microsoft.Office.Interop.PowerPoint.Shape objTriangleShape = objSlide.Shapes.AddShape
(MsoAutoShapeType.msoShapeRightTriangle,
0, 150, 100, 100);
// Add an animation sequence.
Sequence objSequence =
objSlide.TimeLine.InteractiveSequences.Add(1);
// Add text to the shapes.
objSquareShape.TextFrame.TextRange.Text = "Click Me! ";
objTriangleShape.TextFrame.TextRange.Text = "Me Too! ";
// Animate the shapes.
objSequence.AddEffect(objSquareShape,
MsoAnimEffect.msoAnimEffectPathStairsDown,
MsoAnimateByLevel.msoAnimateLevelNone,
MsoAnimTriggerType.msoAnimTriggerOnShapeClick,
1);
objSequence.AddEffect(objTriangleShape,
MsoAnimEffect.msoAnimEffectPathHorizontalFigure8,
MsoAnimateByLevel.msoAnimateLevelNone,
MsoAnimTriggerType.msoAnimTriggerOnShapeClick,
1);
// Save the presentation and run the slide show.
objPres.SaveAs("./test",
PpSaveAsFileType.ppSaveAsPresentation,
MsoTriState.msoTrue);
objPres.SlideShowSettings.Run();
}
}
}
ps:PowerPoint的函数和方法库可在office的帮助文档内查到。
pps:刚刚研究,欢迎讨论....