• 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();
                
            }
        }
    }
    
  • 相关阅读:
    安装xcache3.0.3/3.2,为php加速
    编译安装lamp环境
    使用rpm包安装lamp环境
    centos6下通用二进制安装mysql5.5.33
    centos中进程管理工具
    centos6下的lvm逻辑卷的管理
    centos6中创建软raid方法
    解决vmware虚拟机克隆后启动centos报错device eth0 does not seem to be present, delaying initialization
    centos下常用文件管理命令
    centos下httpd-2.4的编译安装
  • 原文地址:https://www.cnblogs.com/gisoracle/p/5962953.html
Copyright © 2020-2023  润新知