C# 操作PowerPoint(一)

最近想做一个小东西,打算将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:刚刚研究,欢迎讨论....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值