在C#里面给PPT添加注释

平常开会或者做总结报告的时候我们通常都会用到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");
        }
    }
}
posted @   E-iceblue  阅读(1191)  评论(0编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
点击右上角即可分享
微信分享提示