首页 > 代码库 > C# 操作PPt,去掉文本框的边框
C# 操作PPt,去掉文本框的边框
using System;using System.Collections.Generic;using System.Linq;using System.Text;using OFFICECORE = Microsoft.Office.Core;using POWERPOINT = Microsoft.Office.Interop.PowerPoint;using System.Windows;using System.Collections;using System.Windows.Forms;using System.IO;using System.ComponentModel;using System.Data;using System.Drawing;namespace pptWrite{ /// <summary> /// PPT文档操作实现类. /// </summary> public class OperatePPT { #region=========基本的参数信息======= POWERPOINT.Application objApp = null; POWERPOINT.Presentation objPresSet = null; POWERPOINT.SlideShowWindows objSSWs; POWERPOINT.SlideShowTransition objSST; POWERPOINT.SlideShowSettings objSSS; POWERPOINT.SlideRange objSldRng; bool bAssistantOn; #endregion #region===========操作方法============== /// <summary> /// 打开PPT文档并播放显示。 /// </summary> /// <param name="filePath">PPT文件路径</param> public void PPTOpen(string filePath) { //防止连续打开多个PPT程序. if (this.objApp != null) { return; } try { objApp = new POWERPOINT.Application(); objApp.Visible = OFFICECORE.MsoTriState.msoTrue; //以非只读方式打开,方便操作结束后保存. objPresSet = objApp.Presentations.Open(filePath, OFFICECORE.MsoTriState.msoFalse); } catch (Exception ex) { MessageBox.Show("错误:" + ex.Message.ToString()); this.objApp.Quit(); } } /// <summary> /// 自动播放PPT文档. /// </summary> /// <param name="filePath">PPTy文件路径.</param> /// <param name="playTime">翻页的时间间隔.【以秒为单位】</param> public void PPTAuto(string filePath, int playTime) { //防止连续打开多个PPT程序. if (this.objApp != null) { return; } objApp = new POWERPOINT.Application(); objPresSet = objApp.Presentations.Open(filePath, OFFICECORE.MsoTriState.msoCTrue, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse); // 自动播放的代码(开始) int Slides = objPresSet.Slides.Count; int[] SlideIdx = new int[Slides]; for (int i = 0; i < Slides; i++) { SlideIdx[i] = i + 1; }; objSldRng = objPresSet.Slides.Range(SlideIdx); objSST = objSldRng.SlideShowTransition; //设置翻页的时间. objSST.AdvanceOnTime = OFFICECORE.MsoTriState.msoCTrue; objSST.AdvanceTime = playTime; //翻页时的特效! objSST.EntryEffect = POWERPOINT.PpEntryEffect.ppEffectCircleOut; //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 = objPresSet.SlideShowSettings; objSSS.StartingSlide = 1; objSSS.EndingSlide = Slides; objSSS.Run(); //Wait for the slide show to end. objSSWs = objApp.SlideShowWindows; while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(playTime * 100); this.objPresSet.Close(); this.objApp.Quit(); } /// <summary> /// PPT下一页。 /// </summary> public void NextSlide() { if (this.objApp != null) try { this.objPresSet.SlideShowWindow.View.Next(); } catch { } } /// <summary> /// PPT上一页。 /// </summary> public void PreviousSlide() { if (this.objApp != null) this.objPresSet.SlideShowWindow.View.Previous(); } private int PageNum() { return objPresSet.Slides.Count; } public void SetLine() { int num = PageNum(); for (int i = 0; i < num; i++) { if (i > 2) { objSldRng= objPresSet.Slides.Range(i); objSldRng.Select(); try { objSldRng.Application.ActiveWindow.Selection.SlideRange.Shapes.SelectAll(); objSldRng.Application.ActiveWindow.Selection.ShapeRange.Line.Visible = OFFICECORE.MsoTriState.msoFalse; } catch { } //MessageBox.Show("" + i.ToString()); //NextSlide(); } } } /// <summary> /// 关闭PPT文档。 /// </summary> public void PPTClose() { //装备PPT程序。 if (this.objPresSet != null) { //判断是否退出程序,可以不使用。 //objSSWs = objApp.SlideShowWindows; //if (objSSWs.Count >= 1) //{ //if (MessageBox.Show("是否保存修改的笔迹!", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) this.objPresSet.Save(); //} //this.objPresSet.Close(); } if (this.objApp != null) this.objApp.Quit(); GC.Collect(); } #endregion }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace pptWrite{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ylbasicpub.YLCover.selectfilename(this.textBox1, "*.ppt|*.ppt"); } private void Form1_Load(object sender, EventArgs e) { ylbasicpub.YLCover.loadXml(this); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { ylbasicpub.YLCover.SaveXml(this); } private void button2_Click(object sender, EventArgs e) { OperatePPT pOperatePPT = new OperatePPT(); pOperatePPT.PPTOpen(this.textBox1.Text); pOperatePPT.SetLine(); //pOperatePPT.PPTClose(); } }}
C# 操作PPt,去掉文本框的边框
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。