代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C#
】
c# 操作PPT
作者:
Calvin
/ 发布于
2016/3/17
/
395
前段时间要做一个把指定图片放到新建的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(); } } }
试试其它关键字
PPT
同语言下
.
C#实现的html内容截取
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Calvin
贡献的其它代码
(
9
)
.
c# 操作PPT
.
带有进度条的listView
.
内存使用检测
.
交互式命令行,命令行执行 PHP
.
DEBUG 查看调用 backtrace
.
接受 PUT 请求,PHP REST 必备
.
列出所有函数,判断某个函数是否存在
.
变量函数名,可以用字符串拼接函数名
.
返回当前会话的cookie的全部键值
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3