我试图在幻灯片放映模式下直接打开一个PowerPoint演示文稿。我尝试使用一个进程(如下面所示),但是我从PowerPoint获得了一条错误消息,表示它找不到文件,错误消息是"PowerPoint无法读取C://User/路由%20 Plotter.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)。
发布于 2015-09-15 07:44:15
多亏了DavidG,问题就成了斜杠的方向。正斜杠(/)用于URI,反斜杠(\)用于文件路径。将正斜杠替换为反斜杠解决了问题。
发布于 2019-11-15 14:00:40
下面的代码将用于运行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();https://stackoverflow.com/questions/32568349
复制相似问题