在PowerPoint幻灯片访问对象加载 [英] Accessing Slide object in PowerPoint add-in

查看:209
本文介绍了在PowerPoint幻灯片访问对象加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建为PowerPoint中的加载项,需要访问幻灯片或幻灯片对象,甚至整个演示文稿;唉,我可以看到这样做的唯一方法是打开的新的的PPT文件。现在,我不得不求助于保存当前演示文稿和包装重新打开它来操作任何东西(更确切地说,我不得不SHA从PPTX文件的幻灯片对象,看看他们是否已经改变的哈克方法 - 不理想)

I'm building a add-in for PowerPoint and need to access the Slides or Slide objects, or even the whole presentation; alas, the only method I can see of doing this is to open a new ppt file. Right now I'm having to resort to the hacky method of saving the current presentation and reopening it with Packaging to manipulate anything (more specifically I'm having to SHA the Slide objects from the pptx file to see if they've changed -- not ideal)

有什么办法打开目前在PowerPoint中打开W / O不必IO文件?

Is there any way to open the file that is currently open in PowerPoint w/o having to IO a file?

感谢您的帮助,
p

Thanks for your help, P

推荐答案

我假定你已经创建了一个PowerPoint(2007 / 2010)的VisualStudio外接程序项目。一般来说,你可以使用静态类访问当前演示文稿全局是这样的:

I assume you have created a PowerPoint (2007/2010) Add-In Project in VisualStudio. In general you can Access the active presentation with static class Globals this way:

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);

}

这篇关于在PowerPoint幻灯片访问对象加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆