备注是一种特殊的幻灯片,它可以被添加到演示幻灯片以提供提示信息给演讲者。在放映PowerPoint文档时开启演示者视图,演讲者就可以看到幻灯片的内容和备注,而观众则仅能看到幻灯片的内容。
本文将介绍如何使用Spire.Presentation添加备注到PowerPoint文档以及获取现有PowerPoint文档中的备注。
添加备注
C#
//新建PowerPoint文档
Presentation ppt = new Presentation();
//获取第一张幻灯片
ISlide slide = ppt.Slides[0];
//添加备注幻灯片到第一张幻灯片
NotesSlide notesSlide = slide.AddNotesSlide();
TextParagraph paragraph = new TextParagraph();
paragraph.Text = "备注: ";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
//添加第一条备注
paragraph = new TextParagraph();
paragraph.Text = "这是我的第一条备注;";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
notesSlide.NotesTextFrame.Paragraphs[1].BulletType = TextBulletType.Numbered;
notesSlide.NotesTextFrame.Paragraphs[1].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;
//添加第二条备注
paragraph = new TextParagraph();
paragraph.Text = "这是我的第二条备注;";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
notesSlide.NotesTextFrame.Paragraphs[2].BulletType = TextBulletType.Numbered;
notesSlide.NotesTextFrame.Paragraphs[2].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;
//添加第三条备注
paragraph = new TextParagraph();
paragraph.Text = "这是我的第三条备注;";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
notesSlide.NotesTextFrame.Paragraphs[3].BulletType = TextBulletType.Numbered;
notesSlide.NotesTextFrame.Paragraphs[3].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;
//保存文档
ppt.SaveToFile("Notes.pptx", FileFormat.Pptx2013);
VB.NET
'新建PowerPoint文档
Dim ppt As New Presentation()
'获取第一张幻灯片
Dim slide As ISlide = ppt.Slides(0)
'添加备注幻灯片到第一张幻灯片
Dim notesSlide As NotesSlide = slide.AddNotesSlide()
Dim paragraph As New TextParagraph()
paragraph.Text = "备注: "
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph)
'添加第一条备注
paragraph = New TextParagraph()
paragraph.Text = "这是我的第一条备注;"
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph)
notesSlide.NotesTextFrame.Paragraphs(1).BulletType = TextBulletType.Numbered
notesSlide.NotesTextFrame.Paragraphs(1).BulletStyle = NumberedBulletStyle.BulletArabicPeriod
'添加第二条备注
paragraph = New TextParagraph()
paragraph.Text = "这是我的第二条备注;"
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph)
notesSlide.NotesTextFrame.Paragraphs(2).BulletType = TextBulletType.Numbered
notesSlide.NotesTextFrame.Paragraphs(2).BulletStyle = NumberedBulletStyle.BulletArabicPeriod
'添加第三条备注
paragraph = New TextParagraph()
paragraph.Text = "这是我的第三条备注;"
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph)
notesSlide.NotesTextFrame.Paragraphs(3).BulletType = TextBulletType.Numbered
notesSlide.NotesTextFrame.Paragraphs(3).BulletStyle = NumberedBulletStyle.BulletArabicPeriod
'保存文档
ppt.SaveToFile("Notes.pptx", FileFormat.Pptx2013)
获取备注
C#
//加载PowerPoint文档
Presentation ppt = new Presentation();
ppt.LoadFromFile("Notes.pptx");
//获取第一张幻灯片
ISlide slide = ppt.Slides[0];
//获取第一张幻灯片的备注幻灯片
NotesSlide notesSlide = slide.NotesSlide;
//遍历备注幻灯片中的所有段落
foreach (TextParagraph paragraph in notesSlide.NotesTextFrame.Paragraphs)
{
//获取段落文本
string notes = paragraph.Text;
Console.WriteLine(notes);
}
VB.NET
'加载PowerPoint文档
Dim ppt As New Presentation()
ppt.LoadFromFile("Notes.pptx")
'获取第一张幻灯片
Dim slide As ISlide = ppt.Slides(0)
'获取第一张幻灯片的备注幻灯片
Dim notesSlide As NotesSlide = slide.NotesSlide
'遍历备注幻灯片中的所有段落
For Each paragraph As TextParagraph In notesSlide.NotesTextFrame.Paragraphs
'获取段落文本
Dim notes As String = paragraph.Text
Console.WriteLine(notes)
Next