在 Microsoft PowerPoint 中,批注是指可以添加到幻灯片上的短语或段落的一种备注。查看作者添加的批注,读者可以了解更多有关文档内容的信息。同样,读者也可以添加评论以向作者提供意见或反馈。在本文中,您将学习如何使用 Spire.Presentation for .NET 以编程方式在 PowerPoint 幻灯片中添加或删除批注。
安装 Spire.Presentation for .NET
首先,您需要添加 Spire.Presentation for .NET 包中包含的 DLL 文件作为.NET项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.Presentation向演示幻灯片添加批注
详细步骤如下:
- 创建一个 Presentation 实例。
- 使用 Presentation.LoadFromFile() 方法加载 PowerPoint 文档。
- 使用 Presentation.CommentAuthors 属性获取 CommentAuthor 列表。
- 使用 CommentAuthorList.AddAuthor() 方法添加批注的作者。
- 使用 Presentation.Slides[] 属性获取指定幻灯片,然后使用 ISlide.AddComment(ICommentAuthor, String, PointF, DateTime) 方法向幻灯片添加批注。
- 使用 Presentation.SaveToFile() 方法保存结果文档。
- C#
- VB.NET
using Spire.Presentation;
using System;
namespace AddComment
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建一个Presentation实例
            Presentation presentation = new Presentation();
            //加载PowerPoint文档
            presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\Test.pptx");
            //添加批注的作者 
            ICommentAuthor author = presentation.CommentAuthors.AddAuthor("E-iceblue", "批注:");
            //在指定幻灯片添加批注
            presentation.Slides[0].AddComment(author, "Spire.Presentation的功能总结", new System.Drawing.PointF(25, 22), DateTime.Now);
            //保存文档
            presentation.SaveToFile("comment.pptx", FileFormat.Pptx2010);
        }
    }
}Imports Spire.Presentation
Imports System
 
Namespace AddComment
    Class Program
        Shared  Sub Main(ByVal args() As String)
            '创建一个Presentation实例 Dim presentation As Presentation = New Presentation() '加载PowerPoint文档
            presentation.LoadFromFile("C:\Users\Administrator\Desktop\Test.pptx")
 
            '添加批注的作者 Dim author As ICommentAuthor = presentation.CommentAuthors.AddAuthor("E-iceblue","批注:") '在指定幻灯片添加批注
            presentation.Slides(0).AddComment(author,"Spire.Presentation的功能总结",New System.Drawing.PointF(25,22),DateTime.Now)
 
            '保存文档 presentation.SaveToFile("comment.pptx",FileFormat.Pptx2010) End Sub End Class End Namespace
从演示幻灯片中删除批注
详细步骤如下:
- 创建一个 Presentation实例。
- 使用 Presentation.LoadFromFile()方法加载 PowerPoint 文档。
- 使用 Presentation.Slides[]属性获取指定的幻灯片。
- 使用 ISlide.DeleteComment(Comment)方法从指定幻灯片中删除批注。
- 使用 Presentation.SaveToFile()方法保存结果文档。
- C#
- VB.NET
using Spire.Presentation;namespace RemoveComment{class Program{static void Main(string[] args){//创建一个Presentation实例 Presentation presentation = new Presentation();//加载PowerPoint文档 presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\comment.pptx");//获取第一张幻灯片 ISlide slide = presentation.Slides[0];//从指定幻灯片中删除批注 slide.DeleteComment(slide.Comments[0]);//保存文档 presentation.SaveToFile("RemoveComment.pptx",FileFormat.Pptx2010);}}}Imports Spire.Presentation Namespace RemoveComment Class Program Shared Sub Main(ByVal args() As String) '创建一个Presentation实例
            Dim presentation As Presentation =  New Presentation() 
 
            '加载PowerPoint文档 presentation.LoadFromFile("C:\\Users\\Administrator\\Desktop\\comment.pptx") '获取第一张幻灯片
            Dim slide As ISlide =  presentation.Slides(0) 
 
            '从指定幻灯片中删除批注 slide.DeleteComment(slide.Comments(0)) '保存文档
            presentation.SaveToFile("RemoveComment.pptx", FileFormat.Pptx2010) 
 
        End Sub
    End Class
End Namespace
申请临时 License
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
 



 
					



