以幻灯片模式打开 PowerPoint 演示文稿 - C#
Open PowerPoint presentation in slideshow mode - C#
我正在尝试以幻灯片放映模式直接打开 PowerPoint 演示文稿。我已经尝试使用进程(如下所示),但我从 PowerPoint 收到一条错误消息,说找不到文件,错误消息 "PowerPoint can't read C://Users/Route%20Plotter.pptx"。该问题是由文件名中的白色 space 引起的,因为它在删除后有效。
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)
任何想法如何阻止它改变白色 space 到 %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();
我正在尝试以幻灯片放映模式直接打开 PowerPoint 演示文稿。我已经尝试使用进程(如下所示),但我从 PowerPoint 收到一条错误消息,说找不到文件,错误消息 "PowerPoint can't read C://Users/Route%20Plotter.pptx"。该问题是由文件名中的白色 space 引起的,因为它在删除后有效。
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)
任何想法如何阻止它改变白色 space 到 %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();