How do you get the Notes text from the current PowerPoint slide u开发者_JAVA百科sing C#?
I believe this might be what you are looking for:
string s = slide.NotesPage.Shapes[2].TextFrame.TextRange.Text
slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Hello World"
Here is my code that I use for getting the slide notes. Still developing it, but seems to do the trick for the time being. Even in my simple test PPT the slide notes are not always the [2] element in the shapes array, so it is important to check.
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;
}
精彩评论