gpt4 book ai didi

c# - 在 PowerPoint 加载项中访问幻灯片对象

转载 作者:行者123 更新时间:2023-11-30 13:03:30 25 4
gpt4 key购买 nike

我正在为 PowerPoint 构建一个加载项,需要访问幻灯片或幻灯片对象,甚至整个演示文稿;唉,我能看到的唯一方法是打开一个 ppt 文件。现在我不得不求助于保存当前演示文稿并使用 Packaging 重新打开它来操作任何内容的 hacky 方法(更具体地说,我必须对 pptx 文件中的 Slide 对象进行 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);

}

关于c# - 在 PowerPoint 加载项中访问幻灯片对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12688188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com