我想阅读C#中PowerPoint幻灯片的注释.以下代码片段适合我.
slide.NotesPage.Shapes[2].TextFrame.TextRange.Text
Run Code Online (Sandbox Code Playgroud)
但是,这对某些演示文稿不起作用.然后它会抛出"超出范围"的异常.
索引2的含义是什么?有没有替代方法呢?
您不能假设注释文本占位符将位于任何特定索引处,甚至它将具有特定名称.这是VBA中的一个简单函数,它返回幻灯片的notes文本占位符:
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
Run Code Online (Sandbox Code Playgroud)
结束功能