访问PowerPoint加载项中的Slide对象

我正在为PowerPoint构建一个加载项,需要访问幻灯片或幻灯片对象,甚至是整个演示文稿; 唉,我能看到的唯一方法是打开一个新的 ppt文件。 现在,我不得不求助于保存当前演示文稿的hacky方法,并使用Packaging重新打开它来操作任何东西(更具体地说,我需要从pptx文件中删除SHA对象以查看它们是否已更改 – 不理想)

有没有办法打开当前在PowerPoint中打开的文件,无需IO文件?

谢谢你的帮助,P

我假设您已在VisualStudio中创建了PowerPoint(2007/2010)加载项项目。 通常,您可以通过以下方式使用静态类Globals访问活动演示文稿:

 Globals.ThisAddIn.Application.ActivePresentation.Slides[slideIndex] ... 

编辑:用法示例:

 using PowerPoint = Microsoft.Office.Interop.PowerPoint; ... try { int numberOfSlides = Globals.ThisAddIn .Application.ActivePresentation.Slides.Count; if (numberOfSlides > 0) { // get first slide PowerPoint.Slide firstSlide = Globals.ThisAddIn .Application.ActivePresentation.Slides[0]; // get first shape (object) in the slide int shapeCount = firstSlide.Shapes.Count; if (shapeCount > 0) { PowerPoint.Shape firstShape = firstSlide.Shapes[0]; } // add a label PowerPoint.Shape label = firstSlide.Shapes.AddLabel( Orientation: Microsoft.Office.Core .MsoTextOrientation.msoTextOrientationHorizontal, Left: 100, Top: 100, Width: 200, Height: 100); // write hello world with a slidenumber label.TextFrame.TextRange.Text = "Hello World! Page: "; label.TextFrame.TextRange.InsertSlideNumber(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error: " + ex); }