前段时间要做一个把指定图片放到新建的ppt的东西,在网上找了点资料看了一下,发现用C#做好像是最简单的一个,一下是在网上找的一段代码,直接贴进去就能够执行,可是在执行之前一定要加入dll支持:

 项目->加入引用->com->microsoft
office object libraty

 项目->加入引用->com->microsoft
powerpoint object libraty



using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using Microsoft.Office.Core;

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

using Graph = Microsoft.Office.Interop.Graph;

using System.Runtime.InteropServices;



namespace WindowsApplication1

{

    public
partial class Form1 : Form

    {

        public
Form1()

        {

            InitializeComponent();

        }



        private
void button1_Click(object sender, System.EventArgs e)

        {

            ShowPresentation();

            GC.Collect();

        }



        private
void ShowPresentation()

        {

            String
strTemplate, strPic;

            strTemplate
=

              "C:\\Program
Files\\Microsoft Office\\Templates\\Presentation Designs\\Blends.pot";

            strPic
= "C:\\Windows\\Blue Lace 16.bmp";

            bool
bAssistantOn;



            PowerPoint.Application
objApp;

            PowerPoint.Presentations
objPresSet;

            PowerPoint._Presentation
objPres;

            PowerPoint.Slides
objSlides;

            PowerPoint._Slide
objSlide;

            PowerPoint.TextRange
objTextRng;

            PowerPoint.Shapes
objShapes;

            PowerPoint.Shape
objShape;

            PowerPoint.SlideShowWindows
objSSWs;

            PowerPoint.SlideShowTransition
objSST;

            PowerPoint.SlideShowSettings
objSSS;

            PowerPoint.SlideRange
objSldRng;

            Graph.Chart
objChart;



            //Create
a new presentation based on a template.

            objApp
= new PowerPoint.Application();

            objApp.Visible
= MsoTriState.msoTrue;

            objPresSet
= objApp.Presentations;

            objPres
= objPresSet.Open(strTemplate,

             MsoTriState.msoFalse,
MsoTriState.msoTrue, MsoTriState.msoTrue);

            objSlides
= objPres.Slides;



            //Build
Slide #1:

            //Add
text to the slide, change the font and insert/position a

            //picture
on the first slide.

            objSlide
= objSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);

            objTextRng
= objSlide.Shapes[1].TextFrame.TextRange;

            objTextRng.Text
= "My Sample Presentation";

            objTextRng.Font.Name
= "Comic Sans MS";

            objTextRng.Font.Size
= 48;

            objSlide.Shapes.AddPicture(strPic,
MsoTriState.msoFalse, MsoTriState.msoTrue,

             150,
150, 500, 350);



            //Build
Slide #2:

            //Add
text to the slide title, format the text. Also add a chart to the

            //slide
and change the chart type to a 3D pie chart.

            objSlide
= objSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);

            objTextRng
= objSlide.Shapes[1].TextFrame.TextRange;

            objTextRng.Text
= "My Chart";

            objTextRng.Font.Name
= "Comic Sans MS";

            objTextRng.Font.Size
= 48;

            objChart
= (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320,

             "MSGraph.Chart.8",
"", MsoTriState.msoFalse, "", 0, "",

             MsoTriState.msoFalse).OLEFormat.Object;

            objChart.ChartType
= Graph.XlChartType.xl3DPie;

            objChart.Legend.Position
= Graph.XlLegendPosition.xlLegendPositionBottom;

            objChart.HasTitle
= true;

            objChart.ChartTitle.Text
= "Here it is...";



            //Build
Slide #3:

            //Change
the background color of this slide only. Add a text effect to the slide

            //and
apply various color schemes and shadows to the text effect.

            objSlide
= objSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank);

            objSlide.FollowMasterBackground
= MsoTriState.msoFalse;

            objShapes
= objSlide.Shapes;

            objShape
= objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27,

              "The
End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200);

           



            //
自己主动播放的代码(開始)

            //Modify
the slide show transition settings for all 3 slides in

            //the
presentation.

            int[]
SlideIdx = new int[3];

            for
(int i = 0; i < 3; i++) SlideIdx[i] = i + 1;

            objSldRng
= objSlides.Range(SlideIdx);

            objSST
= objSldRng.SlideShowTransition;

            objSST.AdvanceOnTime
= MsoTriState.msoTrue;

            objSST.AdvanceTime
= 3;

            objSST.EntryEffect
= PowerPoint.PpEntryEffect.ppEffectBoxOut;



            //Prevent
Office Assistant from displaying alert messages:

            bAssistantOn
= objApp.Assistant.On;

            objApp.Assistant.On
= false;



            //Run
the Slide show from slides 1 thru 3.

            objSSS
= objPres.SlideShowSettings;

            objSSS.StartingSlide
= 1;

            objSSS.EndingSlide
= 3;

            objSSS.Run();



            //Wait
for the slide show to end.

            objSSWs
= objApp.SlideShowWindows;

            while
(objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);



            //Reenable
Office Assisant, if it was on:

            if
(bAssistantOn)

            {

                objApp.Assistant.On
= true;

                objApp.Assistant.Visible
= false;

            }

            //
自己主动播放的代码(结束)



            //Close
the presentation without saving changes and quit PowerPoint.

            objPres.Close();

            objApp.Quit();

        }

    }

}

c# 操作PPT的更多相关文章

  1. JAVA通过COM接口操作PPT

    一. 背景说明 在Eclipse环境下,开发JAVA代码操作PPT,支持对PPT模板的修改.包括修改文本标签.图表.表格.满足大多数软件生成PPT报告的要求,即先收工创建好模板,在程序中修改模板数据. ...

  2. C++通过COM接口操作PPT

    一. 背景 在VS环境下,开发C++代码操作PPT,支持对PPT模板的修改.包括修改文本标签.图表.表格.满足大多数软件生成PPT报告的要求,先手工创建好PPT模板,在程序中修改模板数据. 二. 开发 ...

  3. java poi 操作ppt

    java poi 操作ppt 可以参考: https://www.w3cschool.cn/apache_poi_ppt/apache_poi_ppt_installation.html http:/ ...

  4. winfrom 操作PPT

    ///winfrom 操作PPT using System; using System.Collections.Generic; using System.Linq; using System.Tex ...

  5. Jacob操作ppt

    前几天使用Apache 的POI操作ppt,后来发现转成的图片出现乱码,而且处理了之后,还会有遗留 因此决定换一种处理方式 Jacob 是 JAVA-COM Bridge的缩写,是一个中间件,能够提供 ...

  6. poi 操作 PPT,针对 PPTX--图表篇

    poi 操作 PPT,针对 PPTX--图表篇 目录 poi 操作 PPT,针对 PPTX--图表篇 1.读取 PPT 模板 2.替换标题 4.替换图表数据 接下来对 ppt 内的图表进行操作,替换图 ...

  7. C#操作PPT表格

    1.激活组件 AxFramerControl改控件的dll自己再网上百度下下载这里不多讲 /// <summary>        /// 检测是否注册控件        /// < ...

  8. C# 操作PPt,去掉文本框的边框

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using OFFICECO ...

  9. (转)C#操作PPT

    原文地址:http://blog.163.com/loveyingchun_1314/blog/static/2382425120124312627530/ 引用Microsoft.Office.Co ...

  10. Java 利用POI操作PPT

    解析PPT文件中的图片 import java.io.File; import java.io.FileOutputStream; import org.apache.poi.hslf.HSLFSli ...

随机推荐

  1. Asp.Net WebApi Action命名中已‘Get’开头问题

    ApiController 中的Action 命名已‘Get’开头,Post方法提交失败 场景: 1.action命名使用Get开头 /// <summary> /// 获取用户的未读消息 ...

  2. IIS应用程序池数目

    今天突然遇到一个问题,访问线上站点,数据处理过之后,访问页面有时是404,有时不是404,而404页面刷新几次之后就正常了. 经过大神们指点之后,发现竟然是应用程序池惹的祸. 分析下原因,在代码里面数 ...

  3. Starting nagios:This account is currently not available nagios

    nagios在启动时报错 # service nagios restartRunning configuration check…done.Stopping nagios: done.Starting ...

  4. iOS 网络与多线程--2.同步Get方式的网络请求(阻塞)

    通过Get请求方式同步获取网络数据.一旦发送同步请求,程序将停止用户交互,直至服务器返回数据. 之后在视图控制器文件(ViewController.m)内添加以下代码 在viewDidLoad函数内添 ...

  5. [HDU1017]Exact cover[DLX][Dancing Links详解][注释例程学习法]

    Dancing Links解决Exact Cover问题. 用到了循环双向十字链表. dfs. 论文一知半解地看了一遍,搜出一篇AC的源码,用注释的方法帮助理解. HIT ACM 感谢源码po主.链接 ...

  6. 32位和64位adb下载及安装

    一.已安装android sdk时 1.拷贝 从%ANDROID_HOME/platform-tools 下拷贝如下文件到/System32和/SysWOW64下即可. adb.exe AdbWinA ...

  7. linux笔记2.21

    命令dmesg显示本次内核启动信息 init是系统运行的第一个进程 Linux运行级别: 0   关机 1   单用户模式 2   不带网络的多用户模式 3   命令行多用户模式  4   未使用 5 ...

  8. 模拟键盘输入首先要用到一个API函数:keybd_event

    转自:http://www.cnblogs.com/cpcpc/archive/2011/02/22/2123055.html 模拟键盘输入首先要用到一个API函数:keybd_event. 模拟按键 ...

  9. C#操作Excel开发报表系列整理(转)

    C#操作Excel进行报表开发系列共写了七篇,也已经有很久没有新东西了,现在整理一下,方便以后查阅,如果有写新的,会同时更新.需要注意的是因为Office的版本不同,实际的代码可能会有所不同,但是都是 ...

  10. phpstorm 2016.1注册码

    phper 享受生产PHP Web开发phpStorm.利用深代码理解,一流的编码的援助,并支持所有主要的工具和框架. 先看看 phpstorm 2016.1 带来那些新变化呢? 1,更好的PHP语言 ...