Spire.Presentation支持开发人员在PowerPoint文档中添加批注以及对现有批注进行各种丰富的操作。本文将介绍如何使用该组件添加批注,编辑和提取批注文本,以及删除批注。
添加批注
C#
//初始化一个Presentation对象
Presentation presentation = new Presentation();
//加载文档
presentation.LoadFromFile("测试文档.pptx");
//设置批注的作者
ICommentAuthor author = presentation.CommentAuthors.AddAuthor("E-iceblue", "E");
//添加批注到第一张幻灯片
presentation.Slides[0].AddComment(author, "E-iceblue产品简介", new PointF(21, 31), DateTime.Now);
//保存文档
presentation.SaveToFile("添加批注.pptx", FileFormat.Pptx2010);
VB.NET
'初始化一个Presentation对象
Dim presentation As New Presentation()
'加载文档
presentation.LoadFromFile("测试文档.pptx")
'设置批注的作者
Dim author As ICommentAuthor = presentation.CommentAuthors.AddAuthor("E-iceblue", "E")
'添加批注到第一张幻灯片
presentation.Slides(0).AddComment(author, "E-iceblue产品简介", New PointF(21, 31), DateTime.Now)
'保存文档
presentation.SaveToFile("添加批注.pptx", FileFormat.Pptx2010)
编辑批注
C#
//初始化一个Presentation对象
Presentation presentation = new Presentation();
//加载文档
presentation.LoadFromFile(@"添加批注.pptx");
//编辑第一张幻灯片的第一个批注
presentation.Slides[0].Comments[0].Text = "修改";
//保存文档
presentation.SaveToFile(@"编辑批注.pptx", FileFormat.Pptx2010);
VB.NET
'初始化一个Presentation对象
Dim presentation As New Presentation()
'加载文档
presentation.LoadFromFile("添加批注.pptx")
'编辑第一张幻灯片的第一个批注
presentation.Slides(0).Comments(0).Text = "修改"
'保存文档
presentation.SaveToFile("编辑批注.pptx", FileFormat.Pptx2010)
提取批注
C#
//初始化一个Presentation对象
Presentation presentation = new Presentation();
//加载文档
presentation.LoadFromFile("添加批注.pptx");
StringBuilder str = new StringBuilder();
//获取第一张幻灯片的所有批注
Comment[] comments = presentation.Slides[0].Comments;
//提取批注文本并保存到文本文档
for (int i = 0; i < comments.Length; i++)
{
str.Append(comments[i].Text + "\r\n");
}
File.WriteAllText("提取批注.txt", str.ToString());
VB.NET
'初始化一个Presentation对象
Dim presentation As New Presentation()
'加载文档
presentation.LoadFromFile("添加批注.pptx")
Dim str As New StringBuilder()
'获取第一张幻灯片的所有批注
Dim comments As Comment() = presentation.Slides(0).Comments
'提取批注文本并保存到文本文档
For i As Integer = 0 To comments.Length - 1
str.Append(comments(i).Text + vbCr & vbLf)
Next
File.WriteAllText("提取批注.txt", str.ToString())
删除批注
C#
//初始化一个Presentation对象
Presentation presentation = new Presentation();
//加载文档
presentation.LoadFromFile(@"添加批注.pptx");
//删除第一张幻灯片的第一个批注
presentation.Slides[0].DeleteComment(presentation.Slides[0].Comments[0]);
//保存文档
presentation.SaveToFile(@"删除批注.pptx", FileFormat.Pptx2010);
VB.NET
'初始化一个Presentation对象
Dim presentation As New Presentation()
'加载文档
presentation.LoadFromFile("添加批注.pptx")
'删除第一张幻灯片的第一个批注
presentation.Slides(0).DeleteComment(presentation.Slides(0).Comments(0))
'保存文档
presentation.SaveToFile("删除批注.pptx", FileFormat.Pptx2010)