无论是在日常的学习还是工作中,PowerPoint都是一种非常实用的文档格式。在制作PPT时,我们有时需要在幻灯片中添加批注。该功能可以帮助我们及时补充有关信息或者注明修改意见。在不需要此项内容时,也可以将其删除。Free Spire.Presentation for .NET就可以帮助我们在C#和VB.NET程序中轻松实现这两个功能。具体操作步骤和相关代码如下:

准备工作:

安装 Free Spire.Presentation for .NET

方法一,通过NuGet安装Free Spire.Presentation for .NET

    依次选择工具>NuGet包管理器>程序包管理器控制台,然后执行以下命令:

PM> Install-Package FreeSpire.Presentation

方法二,在程序中手动引入Spire.Presentation.dll文件:

    将Free Spire.Presentation for .NET 下载到本地,解压并安装。安装完成后,打开 Visual Studio创建新项目,在右边的“解决方案资源管理器”中右键点击“引用”,再依次选择“添加引用”> “浏览”,找到安装路径下BIN文件夹中的dll文件,点击“确定”,将其添加引用至程序中。

为幻灯片添加批注

具体操作步骤:

  • 创建Presentation实例。
  • 使用Presentation.LoadFromFile()方法,加载Powerpoint示例文档。
  • 使用CommentAuthorList.AddAuthor()方法,添加批注作者。
  • 利用 Presentation.Slides[]属性,获取指定幻灯片。
  • 使用ISlide.AddComment(ICommentAuthor, String, PointF, DateTime)方法,为幻灯片添加批注。
  • 使用Presentation.SaveToFile()方法,保存结果文档。

相关代码:

C#:

using Spire.Presentation;
using System;

namespace AddComment
{

    class Program
    {

        static void Main(string[] args)
        {
            //创建Presentation实例
            Presentation presentation = new Presentation();

            //加载Powerpoint示例文档
            presentation.LoadFromFile(@"sample.pptx");

            //添加批注作者 
            ICommentAuthor author = presentation.CommentAuthors.AddAuthor("张三", "批注:");

            //为指定幻灯片添加批注
            presentation.Slides[0].AddComment(author, "世界卫生组织(WHO)是国际上最大的政府间卫生组织。", new System.Drawing.PointF(25, 22), DateTime.Now);
            
            //保存结果文档
            presentation.SaveToFile("comment.pptx", FileFormat.Pptx2010);
        }

    }
}

VB.NET:

Imports Spire.Presentation
Imports System

Namespace AddComment

    Friend Class Program

        Private Shared Sub Main(ByVal args As String())
            '创建Presentation实例
            Dim presentation As Presentation = New Presentation()

            '加载Powerpoint示例文档
            presentation.LoadFromFile("sample.pptx")

            '添加批注作者 
            Dim author As ICommentAuthor = presentation.CommentAuthors.AddAuthor("张三", "批注:")

            '为指定幻灯片添加批注
            presentation.Slides(0).AddComment(author, "世界卫生组织(WHO)是国际上最大的政府间卫生组织。", New Drawing.PointF(25, 22), Date.Now)

            '保存结果文档
            presentation.SaveToFile("comment.pptx", FileFormat.Pptx2010)
        End Sub

    End Class
End Namespace

为幻灯片删除批注

具体操作步骤:

  • 创建Presentation实例。
  • 使用Presentation.LoadFromFile()方法,加载Presentation示例文档。
  • 利用 Presentation.Slides[]属性,获取指定幻灯片。
  • 使用ISlide.DeleteComment(Comment)方法,删除指定幻灯片的批注。
  • 使用Presentation.SaveToFile()方法,保存结果文档。

相关代码:

C#:

using Spire.Presentation;

namespace RemoveComment
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建Presentation实例
            Presentation presentation = new Presentation();

            //加载Presentation示例文档
            presentation.LoadFromFile("comment.pptx");

            //获取指定幻灯片
            ISlide slide = presentation.Slides[0];

            //删除指定幻灯片的批注
            slide.DeleteComment(slide.Comments[0]);

            //保存结果文档
            presentation.SaveToFile("RemoveComment.pptx", FileFormat.Pptx2010);

        }
    }
}

VB.NET:

Imports Spire.Presentation

Namespace RemoveComment
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            '创建Presentation实例
            Dim presentation As Presentation = New Presentation()

            '加载Presentation示例文档
            presentation.LoadFromFile("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

原文地址:http://www.cnblogs.com/Gia-/p/16834783.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性