C# 中的 PowerPoint 笔记
我想阅读 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能假设注释文本占位符将位于任何特定索引处,甚至不能假设它具有特定名称。下面是 VBA 中的一个简单函数,它返回幻灯片的注释文本占位符:
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:
End Function
这意味着您正在尝试访问
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.)
尝试访问索引对象而不首先检查它是否存在是危险的,因为这可能会引发异常。您可以使用幻灯片对象的
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.