C# 中的 PowerPoint 笔记

发布于 2024-11-14 11:38:01 字数 197 浏览 2 评论 0原文

我想阅读 C# 中 PowerPoint 幻灯片的注释。 以下片段对我有用。

slide.NotesPage.Shapes[2].TextFrame.TextRange.Text

但是,这对于某些演示文稿不起作用。 然后它抛出“超出范围”异常。

索引2的含义是什么?有没有其他方法可以做到这一点?

I want to read the notes of a PowerPoint Slide in C#.
Following Snippet works for me.

slide.NotesPage.Shapes[2].TextFrame.TextRange.Text

However, this doesn't work for some presentations.
Then it throws an "Out of range" exception.

What ist the meaning of index 2? Are there any alternative to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独留℉清风醉 2024-11-21 11:38:01

您不能假设注释文本占位符将位于任何特定索引处,甚至不能假设它具有特定名称。下面是 VBA 中的一个简单函数,它返回幻灯片的注释文本占位符:

Function NotesTextPlaceholder(oSl As Slide) As Shape

Dim osh As Shape

For Each osh In oSl.NotesPage.Shapes

    If osh.Type = msoPlaceholder Then
        If osh.PlaceholderFormat.Type = ppPlaceholderBody Then
            ' we found it
            Set NotesTextPlaceholder = osh
            Exit Function
        End If
    End If

Next

End Function

You can't assume that the notes text placeholder will be at any specific index or even that it'll have a specific name. Here's a simple function in VBA that returns the notes text placeholder for a slide:

Function NotesTextPlaceholder(oSl As Slide) As Shape

Dim osh As Shape

For Each osh In oSl.NotesPage.Shapes

    If osh.Type = msoPlaceholder Then
        If osh.PlaceholderFormat.Type = ppPlaceholderBody Then
            ' we found it
            Set NotesTextPlaceholder = osh
            Exit Function
        End If
    End If

Next

End Function

心奴独伤 2024-11-21 11:38:01

这意味着您正在尝试访问 slide.NotesPage.Shapes 集合的第三个元素。如果集合有 2 个或更少的元素,则会抛出异常,因为指定索引 2 处的元素不存在,因此无法访问 - 如果它不存在,您根本无法检索集合的第三个元素没有一个。

(索引从零开始,这意味着第一个元素的索引为0,第二个元素的索引为1,所以因此,具有 N 个元素的集合的最大可能索引是 N-1。)

It means that you are trying to access the third element of the slide.NotesPage.Shapes collection. If the collection has 2 elements or less, the exception is thrown because the element at the specified index 2 could not be accessed since it doesn't exist — you simply cannot retrieve a collection's third element if it doesn't have one.

(The index is zero-based, meaning that the first element is given the index 0, the second one is given the index 1 and so on. Thus, the greatest possible index of a collection with N elements is N-1.)

荆棘i 2024-11-21 11:38:01

尝试访问索引对象而不首先检查它是否存在是危险的,因为这可能会引发异常。您可以使用幻灯片对象的 HasNotesPage 属性检查幻灯片是否有注释:

if(slide.HasNotesPage == Microsoft.Office.Core.MsoTriState.msoTrue)
{

}

如果您想一次获取所有笔记,您可能需要使用 NotesPage 属性来检索包含所有注释的范围。

It's dangerous to try and access an index object without checking if it exists first, since this might throw exceptions. You can check if the slide has notes with the HasNotesPage property of the slide object:

if(slide.HasNotesPage == Microsoft.Office.Core.MsoTriState.msoTrue)
{

}

If you want to get all the notes at once, you might want to use NotesPage property to retrieve a range with all notes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文