平常开会或者做总结报告的时候我们通常都会用到powerpoint演示文稿,我们可以在单个幻灯片或者全部幻灯片里面添加注释,这样观众可以从注释内容里面获取更多的相关信息。
有些朋友不清楚如何在幻灯片里面添加注释,下面我跟大家分享一下如何在c#里面为幻灯片添加注释。
在这里我使用了一个免费控件——free spire.presentation,有兴趣的朋友可以下载使用。
需要添加的命名空间:
1
2
|
using spire.presentation;
using system.drawing;
|
详细步骤和代码片段如下:
步骤1:新建一个presentation对象,从系统里面加载presentation文件。
1
2
|
presentation presentation = new presentation();
presentation.loadfromfile( "sample.pptx" );
|
步骤2:调用commentauthorlist.addauthor(author name, string initials) 方法来添加作者注释。
1
|
icommentauthor author = presentation.commentauthors.addauthor( "e-iceblue" , "comment:" );
|
步骤3:调用call presentation.slides[].addcomment() 方法来给某一张特定幻灯片添加注解。注释的类包含很多信息,像添加注释的作者、添加注释的时间、添加注释的位置和注释的内容。
1
|
presentation.slides[1].addcomment(author, "this part is pretty important. please pay attention to it" , new system.drawing.pointf(42, 4), datetime.now);
|
步骤4:保存并重新打开presentation演示文稿。
1
2
|
presentation.savetofile( "pptwithcomment.pptx" , fileformat.pptx2010);
system.diagnostics.process.start( "pptwithcomment.pptx" );
|
效果图:
全部代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
using system;
using system.collections.generic;
using system.linq;
using system.text;
using spire.presentation;
namespace pptcomment
{
class program
{
static void main( string [] args)
{
//create ppt document and load file
presentation presentation = new presentation();
presentation.loadfromfile( "sample.pptx" );
//comment author
icommentauthor author = presentation.commentauthors.addauthor( "e-iceblue" , "comment:" );
//add comment
presentation.slides[1].addcomment(author, "this part is pretty important. please pay attention to it" , new system.drawing.pointf(42, 4), datetime.now);
//save the document
presentation.savetofile( "pptwithcomment.pptx" , fileformat.pptx2010);
system.diagnostics.process.start( "pptwithcomment.pptx" );
}
}
}
|
以上就是在c#里面给ppt文档添加注释的实现代码,需要的朋友可以参考一下。