我假定你已经创建了一个PowerPoint(2007/2010)加载项项目的VisualStudio。
Globals.ThisAddIn.Application.ActivePresentation.Slides[slideIndex] ...
编辑:一般来说,你可以使用静态类Globals
这种方式访问该活动显示示例用法:
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);
}
非常感谢@JanW。你知道你是否可以安全地序列化/反序列化这个对象来访问它的内容? – user1713993
添加了一个示例。不要考虑序列化/肮脏的工作环境。 Office Interop的ObjectModel已基本完成。您可以通过托管对象访问所有内容,如编辑后的文章。 – JanW
再次感谢并对已故的回复感到抱歉。我现在想要做的是在演示文稿之间复制幻灯片。到目前为止,我能够做到这一点的唯一方法是使用InsertFromFile(),因为我无法直接在ActivePresentation上访问幻灯片对象。我试图通过操作来获得相当低的级别,所以您是否知道是否有方法访问内存中的对象(而不是在任何时候将文件I/O从一个演示文稿复制到另一个演示文稿!)。再次感谢 - 真的很感激它。 – user1713993