前段时间要做一个把指定图片放到新建的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. uploadify在asp.net中的试用小结

    花了差不多一下午的时间,总算把uploadify插件运行起来,在此对自己遇到的问题以及过程做一个小结. 一.使用步骤 1.在官网下载最新的插件包,并将包解压. 2.新建asp.net web项目,将解 ...

  2. Excel连接字符串(Oledb)

    Excel的连接字符串参数详解 2011-07-27 15:43:50|  分类: 编程专栏 |  标签:excel  连接字符串  参数  含义   |字号大中小 订阅     程序中读取Excel ...

  3. (转)JQuery中$.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  4. Android Studio中常用设置与快捷键

    常用设置: 1.Tab不用4个空格Code Style->Java->Tabs and Indents->Use tab characterCode Style->Genera ...

  5. [ERROR] Unknown/unsupported storage engine: InnoDB

    将CentOS上的mysql升级以后,出现无法启动服务的问题.运行mysqld_safe后查看log信息,看到标题所示的错误.搜索以后发现是配置不对,难道两个版本的配置不能互相兼容?那还叫升级?坑爹啊 ...

  6. 用C#实现的条形码和二维码编码解码器

    本文主要介绍可以在C#中使用的1D/2D编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码:二维码也开始应用到很多场合,如火车票有二维码识别.网易的首页有二维码图标,用户只需 ...

  7. JAVA-5-关于for循环的几个例子

    打印一个*组成的矩形 public static void main(String[] args) { // TODO 自动生成的方法存根 for (int i = 0; i < 5; i++) ...

  8. Libevent源码分析(一):最小堆

    Libevent中的timeout事件是使用最小堆来管理维护的.代码位于<minheap-internal.h>. 看函数命名和代码风格应该是一个C++程序员,函数名都挺好懂的,只是下面这 ...

  9. box flex 弹性盒模型(转载)

    css3引入了新的盒模型——弹性盒模型,该模型决定一个盒子在其他盒子中的分布方式以及如何处理可用的空间.这与XUL(火狐使用的用户交互语言)相似,其它语言也使用相同的盒模型,如XAML .GladeX ...

  10. 转载:JSONObject.fromObject(map)(JSON与JAVA数据的转换)

    转载网址:http://blog.sina.com.cn/s/blog_821025b70100wh6v.html JSON与JAVA数据的转换(JSON 即 JavaScript Object Na ...