【问题标题】:Open PowerPoint presentation in slideshow mode - C#以幻灯片模式打开 PowerPoint 演示文稿 - C#
【发布时间】:2023-03-29 19:22:01
【问题描述】:

我正在尝试以幻灯片放映模式直接打开 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 introp 方法(如下),但无法直接以幻灯片模式打开。

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)。

【问题讨论】:

  • 您是否尝试过使用@"path" 作为您的文件路径?
  • 另外你的斜线是错误的,路径应该是C:\Users\Route Plotter.pptx
  • 谢谢大卫。我从另一个应用程序获取路径,甚至没有注意到斜线方向。

标签: c# powerpoint


【解决方案1】:

感谢 DavidG,问题在于斜线的方向。正斜杠 (/) 用于 URI,反斜杠 (\) 用于文件路径。用反斜杠替换正斜杠可以解决此问题。

【讨论】:

    【解决方案2】:

    以下代码将用于运行 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();
    

    【讨论】:

      猜你喜欢
      • 2013-12-14
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多