建立 及 開啟 PowerPoint 檔案 (沒有儲存檔案)

 
建立 及 開啟 PowerPoint 檔案 (沒有儲存檔案)
 

   Form1.cs
 
   using PowerPoint = Microsoft.Office.Interop.PowerPoint;
   using Office = Microsoft.Office.Core;
 
   private void PowerPoint_Create()
   {
 
      PowerPoint.Application PPApp;
      PowerPoint.Presentation PPPres;
      PowerPoint.Slide PPSlide;
 
      PPApp = new PowerPoint.Application();
      PPApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
      PPApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized;
 
      PPPres = PPApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
      PPPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
      PPPres.Slides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
 
      PPPres.Slides[2].Select();
 
      PPSlide = PPPres.Slides[2];
      PPSlide.Delete();
 
      PPPres.Slides[1].Select();
 
      ReleaseObject(PPSlide);
      ReleaseObject(PPPres);
      ReleaseObject(PPApp);
 
   }
 
   private void ReleaseObject(object obj)
   {
 
      try
      {
         System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
         obj = null;
      }
      catch (Exception ex)
      {
         obj = null;
         MessageBox.Show(“Unable to release the Object " + ex.ToString());
      }
      finally
      {
         GC.Collect();
      }
 
   }