예제 #1
0
 public static void CloseInstance()
 {
     if (powerPointApp != null)
     {
         powerPointApp.Quit();
         System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointApp);
         powerPointApp = null;
     }
 }
예제 #2
0
 private void ShutdownPowerPoint( )
 {
     if (_powerPoint == null)
     {
         return;
     }
     try
     {
         _powerPoint.Quit( );
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
         _tracer.TraceException(ex);
     }
     catch (Exception ex)
     {
         _tracer.TraceException(ex);
     }
     COM_Object.Release(_powerPoint);
 }
예제 #3
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建立完毕");
        }
예제 #4
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();
        }