以幻灯片模式打开PowerPoint演示文稿- c#
本文关键字:文稿 PowerPoint 幻灯片 模式 | 更新日期: 2023-09-27 18:12:37
我试图以幻灯片放映模式直接打开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的intrp方法,但是无法在幻灯片模式下直接打开。
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)
下面的代码将用于运行powerpoint的幻灯片放映模式。只要你替换文件路径就足够了。
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();
多亏了DavidG,问题是斜杠的方向。正斜杠(/
)表示URI,反斜杠('
)表示文件路径。用反斜杠替换正斜杠可以解决这个问题。