xiaojunzhu1 2015-01-14 08:53 采纳率: 100%
浏览 3748
已采纳

C#能否实现将一个PPT中的一页复制到另一个PPT中?

C#能否实现将一个PPT中的一页复制到另一个PPT中? 不知道有没有什么办法

  • 写回答

2条回答

  • shiter 人工智能领域优质创作者 2015-01-14 11:31
    关注

    下面是操作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.Controls;
    
    namespace PPTDraw.PPTOperate
    {
        /// <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;
            double pixperPoint = 0;
            double offsetx = 0;
            double offsety = 0;
            #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();
                    //以非只读方式打开,方便操作结束后保存.
                    objPresSet = objApp.Presentations.Open(filePath, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse);
    
                    //Prevent Office Assistant from displaying alert messages:
                    bAssistantOn = objApp.Assistant.On;
                    objApp.Assistant.On = false;
    
                    objSSS = this.objPresSet.SlideShowSettings;
                    objSSS.Run();
                }
                catch (Exception ex)
                {
                    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)
                    this.objPresSet.SlideShowWindow.View.Next();
            }
            /// <summary>
            /// PPT上一页。
            /// </summary>
            public void PreviousSlide()
            {
                if (this.objApp != null)
                    this.objPresSet.SlideShowWindow.View.Previous();
            }
    
            /// <summary>
            /// 对当前的PPT页面进行图片插入操作。
            /// </summary>
            /// <param name="alImage">图片对象信息数组</param>
            /// <param name="offsetx">插入图片距离左边长度</param>
            /// <param name="pixperPoint">距离比例值</param>
            /// <returns>是否添加成功!</returns>
            public bool InsertToSlide(List<PPTOBJ> listObj)
            {
                bool InsertSlide = false;
                if (this.objPresSet != null)
                {
                    this.SlideParams();
                    int slipeint = objPresSet.SlideShowWindow.View.CurrentShowPosition;
    
                    foreach (PPTOBJ myobj in listObj)
                    {
                        objPresSet.Slides[slipeint].Shapes.AddPicture(
                             myobj.Path,           //图片路径
                             OFFICECORE.MsoTriState.msoFalse,
                             OFFICECORE.MsoTriState.msoTrue,
                             (float)((myobj.X - this.offsetx) / this.pixperPoint),       //插入图片距离左边长度
                             (float)(myobj.Y / this.pixperPoint),       //插入图片距离顶部高度
                             (float)(myobj.Width / this.pixperPoint),   //插入图片的宽度
                             (float)(myobj.Height / this.pixperPoint)   //插入图片的高度
                          );
                    }
                    InsertSlide = true;
                }
                return InsertSlide;
            }
    
            /// <summary>
            /// 计算InkCanvas画板上的偏移参数,与PPT上显示图片的参数。
            /// 用于PPT加载图片时使用
            /// </summary>
            private void SlideParams()
            {
                double slideWidth = this.objPresSet.PageSetup.SlideWidth;
                double slideHeight = this.objPresSet.PageSetup.SlideHeight;
                double inkCanWidth = SystemParameters.PrimaryScreenWidth;//inkCan.ActualWidth;
                double inkCanHeight = SystemParameters.PrimaryScreenHeight;//inkCan.ActualHeight ;
    
                if ((slideWidth / slideHeight) > (inkCanWidth / inkCanHeight))
                {
                    this.pixperPoint = inkCanHeight / slideHeight;
                    this.offsetx = 0;
                    this.offsety = (inkCanHeight - slideHeight * this.pixperPoint) / 2;
                }
                else
                {
                    this.pixperPoint = inkCanHeight / slideHeight;
                    this.offsety = 0;
                    this.offsetx = (inkCanWidth - slideWidth * this.pixperPoint) / 2;
                }
            }
            /// <summary>
            /// 关闭PPT文档。
            /// </summary>
            public void PPTClose()
            {
                //装备PPT程序。
                if (this.objPresSet != null)
                {
                    //判断是否退出程序,可以不使用。
                    //objSSWs = objApp.SlideShowWindows;
                    //if (objSSWs.Count >= 1)
                    //{
                        if (MessageBox.Show("是否保存修改的笔迹!", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                            this.objPresSet.Save();
                    //}
                    //this.objPresSet.Close();
                }
                if (this.objApp != null)
                    this.objApp.Quit();
    
                GC.Collect();
            }
            #endregion
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?