How to programmatically read and change slide notes in PowerPoint

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 02:48:50

问题


How do you get the Notes text from the current PowerPoint slide using C#?


回答1:


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"



回答2:


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;
    }


来源:https://stackoverflow.com/questions/2164819/how-to-programmatically-read-and-change-slide-notes-in-powerpoint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!