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)