如何使用C#从当前的PowerPoint幻灯片中获取Notes文本?
答案 0 :(得分:4)
我相信这可能就是你要找的东西:
string s = slide.NotesPage.Shapes[2].TextFrame.TextRange.Text
slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Hello World"
答案 1 :(得分:1)
这是我用于获取幻灯片备注的代码。仍在开发它,但似乎暂时做了伎俩。即使在我的简单测试PPT中,幻灯片音符并不总是形状数组中的[2]元素,因此检查它是很重要的。
private string GetNotes(Slide slide)
{
if (slide.HasNotesPage == MsoTriState.msoFalse)
return string.Empty;
string slideNodes = string.Empty;
var notesPage = slide.NotesPage;
int length = 0;
foreach (Shape shape in notesPage.Shapes)
{
if (shape.Type == MsoShapeType.msoPlaceholder)
{
var tf = shape.TextFrame;
try
{
//Some TextFrames do not have a range
var range = tf.TextRange;
if (range.Length > length)
{ //Some have a digit in the text,
//so find the longest text item and return that
slideNodes = range.Text;
length = range.Length;
}
Marshal.ReleaseComObject(range);
}
catch (Exception)
{}
finally
{ //Ensure clear up
Marshal.ReleaseComObject(tf);
}
}
Marshal.ReleaseComObject(shape);
}
return slideNodes;
}