2012-03-08 76 views
2

任何人都知道如何製作一個或如何下載控件來查看PowerPoint文檔?Powerpoint Viewer控件C#/ VB/.NET

我查過了,但是唯一出現的是this,這絕對不是免費的。我相信微軟必須擁有一個能夠做到這一點的控制。

做一個控制,做它也歡迎。

+0

這被討論過很多次,最好的辦法似乎是使用Web瀏覽器控件來顯示PPT文件,見前面的問題,例如:http://stackoverflow.com/questions/1259369/embed-powerpoint-viewer -in-c-sharp-win-form – 2012-03-08 17:11:48

回答

4

這裏有我正在尋找的問題的解決方案。 如果任何人有同樣的問題,我離開這裏後,我做了很多小時的工作後,我的解決方案。

 [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] 
     static extern IntPtr FindWindow(IntPtr ZeroOnly, string lpWindowName); 

     [DllImport("user32.dll", SetLastError = true)] 
     static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 

     [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 
     public static extern bool SetWindowText(IntPtr hwnd, String lpString); 


     private string FileName = ""; 
     PowerPoint.Application application; 
     PowerPoint.Presentation presentation; 
     bool flag = false; 

     public UserControl1() 
     { 
      InitializeComponent(); 
     } 


     public void open() 
     { 
      sair(); 

      openFileDialog1.Filter = "Powerpoint file (*.ppt)|*.ppt|All files (*.*)|*.*"; 

      if (openFileDialog1.ShowDialog() == DialogResult.OK) 
      { 
       FileName = openFileDialog1.FileName; 

       IntPtr screenClasshWnd = (IntPtr)0; 
       IntPtr x = (IntPtr)0; 

       flag = true; 

       application = new PowerPoint.Application(); 
       presentation = application.Presentations.Open2007(FileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue); 
       PowerPoint.SlideShowSettings sst1 = presentation.SlideShowSettings; 


       sst1.ShowType = (PowerPoint.PpSlideShowType)1; 
       PowerPoint.SlideShowWindow sw = sst1.Run(); 


       sw.Height = (panel1.Height) - 64; 
       sw.Width = (panel1.Width) - 130; 

       IntPtr formhWnd = FindWindow(x, "Form1"); 
       IntPtr pptptr = (IntPtr)sw.HWND; 
       screenClasshWnd = FindWindow(x, "screenClass"); 
       SetParent(pptptr, panel1.Handle); 

       this.Focus(); 

       this.application.SlideShowEnd += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowEndEventHandler(SlideShowEnds); 
      } 
     } 
+0

中鏈接了什麼嗨,這看起來非常有趣@NickHalden,但我看不出有些東西在哪裏定義,例如sair()方法? – KingCronus 2012-07-08 10:29:03

1

最簡單的方法是使用PowerPoint Interop名稱空間。你可以在MSDN site上閱讀。一個警告,是它需要你安裝PowerPoint。所以,如果這將用於商業軟件,那麼這將是沒有實際意義的,因爲客戶不得不購買PowerPoint。但是對於許多任務來說,它很漂亮,而.NET 4.0使得MS Office的工作變得簡單。

+0

我已經使用PowerPoint Interop,但它不是我想要的。 我想用ppt查看器將其嵌入到c#窗口中,唯一的方法是創建或使用ppt查看器作爲控件。 PowerPoint Interop創建PowerPoint實例並使用全屏顯示。 – diogopalhais 2012-03-08 18:03:19

+0

@NickHalden然後我會建議看看Davide Piras在評論 – Jetti 2012-03-08 18:40:54