前段时间要做一个把指定图片放到新建的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. JQuery图片轮换 nivoSlider图片轮换

    效果图: 第一步:添加引用 <script src="jquery-ui-1.9.2.custom.min.js" type="text/javascript&qu ...

  2. Android开发中在一个Activity中关闭另一个Activity

    比如有ActivityA, ActivityB,在ActivityB中关闭ActivityA 解决方案: 1. 在 ActivityA 里面设置一个静态的变量instance,初始化为this在 Ac ...

  3. AJAX校验用户名是否存在,焦点离开用户名、点击 【 检 查用户名 】的校验。分别用 XMLHttp 和 JQueryAJAX实现。

     XMLHttp方法: $("#name").blur(function () { var xmlhttp = new ActiveXObject("Microsoft. ...

  4. Ubuntu11.10与r8168网卡不兼容导致网络时断时续的问题

    安装了ubuntu11.10之后,感觉上网啥的很不稳定,ssh连接内网机器也是一条命令卡半天,检查了各方面的原因,网络没有什么问题,最后才发现是网卡驱动的问题,网上搜了一下是由于linux(ubunt ...

  5. java操作csv文件之javacsv.jar应用

    csv文件是分隔文件,如果使用java的io流来写,比较麻烦,这里为大家提供一个javacsv的jar包,这个很方便操作csv文件. 下载地址:https://pan.baidu.com/s/1i46 ...

  6. JavaScript 之 使用 XMLHttpRequest 预览文件(图片)

    <div id="div1"> <input type="file" id="uploadfile" style=&quo ...

  7. oracle单行函数之通用函数

    NVL (a,b) --当a=null时,返回b,否则返回a NVL2 (a, b, c) -- 当a=null时,返回c,否则返回b NULLIF (expr1, expr2) --当a=b时,返回 ...

  8. jquery中的replaceWith()和html()有什么区别?

    区别在于,html()会替换指定元素内部的HTML,而replaceWith()会替换元素本身及其内部的HTML. 例子: 1 <div id="myid" /> 1 ...

  9. 11061160顾泽鹏homework-01

    我的Github地址是buaa11061160 教材:中文版 代码大全 (第二版) 斯蒂夫·迈克康奈尔 设计思路: 输入了一串数组a[0].a[1]..... 从a[0]开始向后扫,在以数字a[i]结 ...

  10. 【学习笔记】【oc】Block

    块(block):类似于定义一个匿名的函数.至于其他什么用处我就不知道了 块的定义: ^[块返回值类型](形参类型1 形参1, 形参类型2 形参2,...) { //块执行体 } 跟函数语法格式的差别 ...