我正在构建 PowerPoint 加载项,需要访问幻灯片或幻灯片对象,甚至整个演示文稿;唉,我能看到的唯一方法就是打开一个newppt 文件。现在,我不得不求助于保存当前演示文稿并使用打包重新打开它来操作任何内容的黑客方法(更具体地说,我必须对 pptx 文件中的幻灯片对象进行 SHA 处理,以查看它们是否已更改 -不理想)
有没有办法打开当前在 PowerPoint 中打开的文件而无需 IO 文件?
感谢您的帮助,
磷
我假设您已在 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)