C# 操作PowerPoint(一)
2014-02-11 16:40
429 查看
最近想做一个小东西,打算将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:刚刚研究,欢迎讨论....
首先,环境是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:刚刚研究,欢迎讨论....
相关文章推荐
- C# PowerPoint操作的基本用法[转]
- C# PowerPoint操作的基本用法
- C# 操作Powerpoint
- C# PowerPoint操作的基本用法
- C# PowerPoint操作的基本用法
- C# PowerPoint操作的基本用法。
- C#操作PowerPoint的方法
- C# PowerPoint操作的基本用法。
- C# PowerPoint操作的基本用法。
- 使用P/Invoke、C#与Windows Media Player互操作(一)
- c#文件操作
- C#与TXT文件的读写操作
- C#操作高低位
- 使用c#操作txt
- C# 操作EXCEL导出数据报表的类
- 在C#中使用NPOI2.0操作Excel2003和Excel2007
- c#操作excel时出现COM异常,解决方法
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- C# XML序列化操作菜单
- C#操作Excel文件~创建Excel文件