예제 #1
0
        // Test driver.
        public static bool Test()
        {
            bool passed = true;

            PowerPoint.Application app = new PowerPoint.Application();
            //PowerPoint.Application app = new PowerPoint.ApplicationClass();
            app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

            PowerPoint.Presentation presentation = app.Presentations.Add(Core.MsoTriState.msoFalse);
            PowerPoint.Slide        slide        = presentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
            PowerPoint.Shape        shape        = slide.Shapes.AddLine(0, 0, 100, 100);

            Console.WriteLine("Test on presentation.");
            passed = passed && TestTags(presentation.Tags);

            Console.WriteLine("Test on slide.");
            passed = passed && TestTags(slide.Tags);

            Console.WriteLine("Test on shape.");
            passed = passed && TestTags(shape.Tags);

            app = null;

            return(passed);
        }
예제 #2
0
 public static void InitializeInstance()
 {
     if (powerPointApp == null)
     {
         powerPointApp = new PowerPoint.ApplicationClass();
     }
 }
예제 #3
0
 public static void CloseInstance()
 {
     if (powerPointApp != null)
     {
         powerPointApp.Quit();
         System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointApp);
         powerPointApp = null;
     }
 }
예제 #4
0
 private void CheckPath(string p)
 {
     try
     {
         if (string.IsNullOrEmpty(p))
         {
             foreach (string s in Directory.GetFiles(AppPath + "\\PPT", "*.ppt", SearchOption.TopDirectoryOnly))
             {
                 PPTPath = s;
                 break;
             }
         }
         else
         {
             PPTPath = p;
         }
         PPTPath = PPTPath.Replace(AppPath, ".");
         if (!string.IsNullOrEmpty(PPTPath) && File.Exists(PPTPath))
         {
             FileInfo fi   = new FileInfo(PPTPath);
             string   path = fi.DirectoryName + "\\" + fi.Name.Replace(fi.Extension, string.Empty);
             bool     err  = false;
             if (Directory.Exists(path))
             {
                 if (Directory.GetFiles(path, "*.jpg", SearchOption.TopDirectoryOnly).Length == 0)
                 {
                     err = true;
                     Directory.Delete(path, true);
                 }
             }
             else
             {
                 err = true;
             }
             if (err)
             {
                 PowerPoint.Presentation pr = new PowerPoint.Application().Presentations.Open((PPTPath.StartsWith(".") ? AppPath + PPTPath.TrimStart('.') : PPTPath), PowerPoint.MsoTriState.msoTrue, PowerPoint.MsoTriState.msoFalse, PowerPoint.MsoTriState.msoFalse);
                 pr.SaveAs(path + ".jpg", PowerPoint.PpSaveAsFileType.ppSaveAsJPG, PowerPoint.MsoTriState.msoTrue);
                 pr.Close();
             }
             foreach (string s in Directory.GetFiles(path, "*.jpg", SearchOption.TopDirectoryOnly))
             {
                 ImageBrush b = new ImageBrush();
                 b.ImageSource   = new BitmapImage(new Uri(s, UriKind.RelativeOrAbsolute));
                 b.Stretch       = Stretch.UniformToFill;
                 Bor1.Background = b;
                 break;
             }
             DS.Tables[0].Rows.Find(br.Name)[1] = PPTPath;
             DS.WriteXml(AppPath + "\\ShowPPT.Dat", System.Data.XmlWriteMode.WriteSchema);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #5
0
 private void Bor1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         if (e.ClickCount == 2 && !string.IsNullOrEmpty(PPTPath))
         {
             PowerPoint.Application       ap  = new PowerPoint.Application();
             PowerPoint.SlideShowSettings sss = ap.Presentations.Open((PPTPath.StartsWith(".") ? AppPath + PPTPath.TrimStart('.') : PPTPath), PowerPoint.MsoTriState.msoTrue, PowerPoint.MsoTriState.msoFalse, PowerPoint.MsoTriState.msoFalse).SlideShowSettings;
             SetWindowPos(new IntPtr(ap.HWND), -1, 0, 0, 0, 0, 1 | 4);
             sss.Run();
         }
     }
     catch (Exception EX)
     {
         MessageBox.Show(EX.Message);
     }
 }
예제 #6
0
 private void InitializePowerPoint()
 {
     if (_powerPoint != null)
     {
         return;
     }
     try
     {
         _powerPoint = new PowerPoint.ApplicationClass();
         if (_powerPoint != null)
         {
             _powerPoint.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
         }
     }
     catch (Exception ex)
     {
         _tracer.Trace("Cannot load MSPowerPoint");
         _tracer.TraceException(ex);
     }
 }
예제 #7
0
        private void ppt_start()
        {
            if (pptApp != null)
            {
                log("尝试关闭旧的ppt程序...");
                try
                {
                    log("释放旧的ppt com对象...");
                    pptApp.Quit();
                    Marshal.ReleaseComObject(pptApp);
                }
                catch (Exception e)
                {
                    error("释放ppt com对象失败{0}...内存泄漏+1", e.Message);
                }
            }

            killOldProcess(ppt_name);
            pptApp = new PowerPoint.Application();
            log("ppt com建立完毕");
        }
        public bool GetOpenPpt()
        {
            bool success = false;

            try
            {
                // Get Running PowerPoint Application object
                pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PowerPoint.Application;
            }
            catch
            {
            }

            if (pptApplication != null)
            {
                success = true;

                // Get Presentation Object
                presentation = pptApplication.ActivePresentation;
                // Get Slide collection object
                slides = presentation.Slides;
                // Get Slide count
                slidesCount = slides.Count;
                // Get current selected slide
                try
                {
                    // Get selected slide object in normal view
                    slide = slides[pptApplication.ActiveWindow.Selection.SlideRange.SlideNumber];
                }
                catch
                {
                    // Get selected slide object in reading view
                    slide = pptApplication.SlideShowWindows[1].View.Slide;
                }
            }

            return(success);
        }
예제 #9
0
 /// <summary>
 /// 将PPT文件转化成Pdf(提供给OfficeConvertPdf方法调用)(使用插件:Microsoft.Office.Interop.PowerPoint.Dll,Office.Dll)
 /// </summary>
 /// <param name="pptPath">源存放Ppt文件地址</param>
 /// <param name="pdfPath">转换后存放Pdf文件的地址</param>
 private static void PptConvertPdf(string pptPath, string pdfPath)
 {
     try
     {
         if (!File.Exists(pptPath))
         {
             throw new System.Exception("不存在源文件,PPT不存在");
         }
         if (string.IsNullOrEmpty(pdfPath))
         {
             throw new System.Exception("转换存放PDF的路径不能为空");
         }
         //进行转换
         var powerPoint       = new PowerPoint.Application();                       //插件:Microsoft.Office.Interop.PowerPoint.Dll
         var objPresentations = powerPoint.Presentations.Open(pptPath, MsoTriState.msoFalse, MsoTriState.msoFalse,
                                                              MsoTriState.msoTrue); //插件:Office.Dll
         //调用转换PPT转换Pdf的方法
         To_PptConvertPdf(objPresentations, pdfPath);
     }
     catch (System.Exception exception)
     {
         throw new System.Exception("PPT转换PDF出现错误了,错误原因:" + exception.Message);
     }
 }
예제 #10
0
            /// <summary>
            /// 将PPT文件转化成Pdf(提供给OfficeConvertPdf方法调用)(使用插件:Microsoft.Office.Interop.PowerPoint.Dll,Office.Dll)
            /// </summary>
            /// <param name="pptPath">源存放Ppt文件地址</param>
            /// <param name="pdfPath">转换后存放Pdf文件的地址</param>
            private static void PptConvertPdf(string pptPath, string pdfPath)
            {
                try
                {
                    if (!File.Exists(pptPath))
                    {
                        throw new System.Exception("不存在源文件,PPT不存在");
                    }
                    if (string.IsNullOrEmpty(pdfPath))
                    {
                        throw new System.Exception("转换存放PDF的路径不能为空");
                    }
                    //进行转换
                    var powerPoint = new PowerPoint.Application(); //插件:Microsoft.Office.Interop.PowerPoint.Dll
                    var objPresentations = powerPoint.Presentations.Open(pptPath, MsoTriState.msoFalse, MsoTriState.msoFalse,
                        MsoTriState.msoTrue); //插件:Office.Dll
                                              //调用转换PPT转换Pdf的方法
                    To_PptConvertPdf(objPresentations, pdfPath);

                }
                catch (System.Exception exception)
                {
                    throw new System.Exception("PPT转换PDF出现错误了,错误原因:" + exception.Message);
                }
            }
예제 #11
0
        private void ShowPresentation()
        {
            String strDest = Environment.CurrentDirectory + "\\" + txtSaveAs.Text + ".ppt";

            PowerPoint.Application       objApp;
            PowerPoint.Presentations     objPresSet;
            PowerPoint._Presentation     objPres;
            PowerPoint.SlideShowSettings objSSS;
            PowerPoint.SlideShowWindows  objSSWs;

            //Create a new presentation based on a template.
            objApp         = new PowerPoint.Application();
            objApp.Visible = MsoTriState.msoTrue;
            objPresSet     = objApp.Presentations;

            int iCurCnt   = 1;
            int iSlideCnt = 0;

            objPres = objPresSet.Add(Microsoft.Office.Core.MsoTriState.msoFalse);

            for (int i = 0; i < lstList.Items.Count; i++)
            {
                PowerPoint._Presentation objPresOpen;

                objPresOpen = objPresSet.Open(lstList.Items[i].Text, MsoTriState.msoTrue, MsoTriState.msoTrue,
                                              MsoTriState.msoFalse);
                iSlideCnt = objPresOpen.Slides.Count;

                objPres.Slides.InsertFromFile(lstList.Items[i].Text, iCurCnt - 1, 1, iSlideCnt);

                for (int j = 1, iCount = iCurCnt; j <= iSlideCnt; j++, iCount++)
                {
                    PowerPoint.Slide slide = objPres.Slides.Item(iCount);
                    slide.Design                 = objPresOpen.Slides.Item(j).Design;
                    slide.ColorScheme            = objPresOpen.Slides.Item(j).ColorScheme;
                    slide.FollowMasterBackground = MsoTriState.msoTrue;
                    slide.DisplayMasterShapes    = MsoTriState.msoTrue;
                }

                objPresOpen.Close();

                iCurCnt += iSlideCnt;
            }

            objPres.SaveAs(strDest, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
                           MsoTriState.msoTrue);

            objPres.Close();


            objPres = objPresSet.Open(strDest, MsoTriState.msoTrue, MsoTriState.msoTrue,
                                      MsoTriState.msoTrue);

            //Prevent Office Assistant from displaying alert messages:
            objApp.Assistant.On      = false;
            objApp.Assistant.Visible = false;


            //Run the Slide show from slides 1 thru 3.
            objSSS = objPres.SlideShowSettings;
            objSSS.StartingSlide = 1;
            objSSS.EndingSlide   = iCurCnt - 1;
            objSSS.Run();

            //Wait for the slide show to end.
            objSSWs = objApp.SlideShowWindows;
            while (objSSWs.Count >= 1)
            {
                System.Threading.Thread.Sleep(100);
            }

            //Close the presentation without saving changes and quit PowerPoint.
            objPres.Close();
            objApp.Quit();
        }
예제 #12
0
        private const int SHAPEMARGIN = 8; // the margin of error for clicking on a shape

        //internal int choiceCounter; // counts the number of shapes that a mouseDown falls within
        #endregion


        #region Constructors
        /// <summary>
        /// Constructor that initializes pptApp
        /// </summary>
        /// <param name="inputApp">the current application</param>
        public PPTcontrol(object inputApp)
        {
            pptApp = (PowerPoint.Application)inputApp;
        }//end constructor for pptcontrol