c# - C#打开PPTX文件到特定幻灯片索引
问题描述
我正在查看打开特定幻灯片索引的 .pptx PowerPoint 文件。对于此示例,假设幻灯片 3。
我有打开文件的代码,但我不能让它自己打开到幻灯片 3。
打开pptx文件的代码:
string file_path = @"C:\Users\Me\Desktop\Test_Folder\myppt.pptx";
Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue;
pptApp.Visible = otrue;
pptApp.Activate();
Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(file_path, ofalse, ofalse, otrue);
System.Diagnostics.Debug.Print(p.Windows.Count.ToString());
我已经阅读了一些内容,我解决这个问题的想法包括添加一个位置,p.Slides[2]
将其发送到幻灯片索引 3(认为它像数组一样变为 0、1、2,我在这里可能是错的)。我只是不知道将它放在我的代码块中的哪个位置,或者如果有不同的方式,我还没有看到。
解决方案
根据评论中的 Icemanind,在p.Open
上述代码行之后添加两行,电源点打开到正确的幻灯片。
这两行是:
p.SlideShowSettings.Run()
p.SlideShowWindow.View.GotoSlide(3, MsoTriState.msoFalse);
功能代码:
string file_path = @"C:\Users\Me\Desktop\Test_Folder\myppt.pptx";
Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue;
pptApp.Visible = otrue;
pptApp.Activate();
Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(file_path, ofalse, ofalse, otrue);
p.SlideShowSettings.Run()
p.SlideShowWindow.View.GotoSlide(3, MsoTriState.msoFalse);
System.Diagnostics.Debug.Print(p.Windows.Count.ToString());
推荐阅读
- chart.js - Chart.js 标签和点在右侧截断
- ansible - 在 Ansible 循环中,从注册结果中测试文件是否存在
- ios - 如何在 iOS 13 中识别用户最后一次交互的 UIScene
- python-3.x - 带有 conda 集成的 pySpark 抛出错误 pyspark 无法识别
- node.js - NodeJS / Express:发生不一致的[ERR_HTTP_HEADERS_SENT]
- java - 多次重启后如何唯一标识一个java进程
- python - 如何从熊猫数据框中的一列列表中的列表中随机选择
- android - 无法在 Android Studio 上重新打开组件树
- php - 未定义属性:stdClass::$Unblinking Eternity
- python - Python - 使用 scipy.stats.hypergeom 进行矢量化操作