簡體   English   中英

以幻燈片模式打開 PowerPoint 演示文稿 - C#

[英]Open PowerPoint presentation in slideshow mode - C#

我正在嘗試在幻燈片放映模式下直接打開 PowerPoint 演示文稿。 我已經嘗試使用進程(如下所示),但是我從 PowerPoint 收到一條錯誤消息,說它找不到文件,錯誤消息“PowerPoint 無法讀取 C://Users/Route%20Plotter.pptx” . 該問題是由文件名中的空格引起的,因為它在刪除時起作用。

string powerPointPath = @"C:\Program Files\Microsoft Office   15\root\office15\powerpnt.exe";
string powerPointFilePath = "\"" + "C://Users/Route Plotter.pptx" + "\"";

Process powerPoint = new Process();
powerPoint.StartInfo.FileName = powerPointPath;
powerPoint.StartInfo.Arguments = " /S " + powerPointFilePath;
powerPoint.Start();

我已經嘗試使用 Office 介紹方法(如下),但無法直接在幻燈片模式下打開。

Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
pptApp.Activate();

Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(powerPointFilePath, 
            Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue)

任何想法如何停止將空格更改為 %20(我已經在路徑周圍添加引號),或將文件直接打開為幻燈片模式的另一種方法,將不勝感激。

(我使用的是 VS2013 和 PowerPoint 2013)。

感謝 DavidG,問題是斜線的方向。 正斜杠 ( / ) 用於 URI,反斜杠 ( \\ ) 用於文件路徑。 用反斜杠替換正斜杠可以解決這個問題。

以下代碼將用於運行 Power Point 的幻燈片放映模式。 只要你替換文件路徑就足夠了。

        Application ppApp = new Application();
        ppApp.Visible = MsoTriState.msoTrue;

        Presentations ppPresens = ppApp.Presentations;
        Presentation objPres = ppPresens.Open("C:\\Users\\Users\\Documents\\Projects\\LS\\WindowsFormsApp1\\PPT.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
        Slides objSlides = objPres.Slides;

        SlideShowWindows objSSWs;
        SlideShowSettings objSSS;
        //Run the Slide show                                
        objSSS = objPres.SlideShowSettings;
        objSSS.Run();
        objSSWs = ppApp.SlideShowWindows;
        while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);
        //Close the presentation without saving changes and quit PowerPoint                             
        objPres.Close();
        ppApp.Quit();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM