首页 > 编程语言 >如何在C#/VB.NET程序中为幻灯片添加或删除批注

如何在C#/VB.NET程序中为幻灯片添加或删除批注

时间:2022-10-28 09:45:01浏览次数:70  
标签:批注 VB C# Presentation 文档 NET presentation 幻灯片

无论是在日常的学习还是工作中,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

标签:批注,VB,C#,Presentation,文档,NET,presentation,幻灯片
From: https://www.cnblogs.com/Gia-/p/16834783.html

相关文章

  • 马扎克全系列机床数据采集 Smooth C, Smooth G,Smooth X,Smart, Matrix Nexu2, 640MT,
     internalstaticexternintMazConnect(refushortparam0,[MarshalAs(UnmanagedType.LPStr),In]stringparam1,intparam2,intparam3);[DllImport("NTIFDLL")......
  • AMD Xilinx MPSoC Linux加载bit文件
    AMDXilinxMPSoCLinux加载bit文件草稿目录总结概述OverviewLinux加载fullbitLinux加载fullbit和devicetreeLinux加载partialbitLinux加载partialbit和......
  • caffe python 不打印
    不打印如下信息I102809:21:03.1102155174net.cpp:338]pool1doesnotneedbackwardcomputation.I102809:21:03.1102175174net.cpp:338]conv1_2/reludoesno......
  • react 受控组件与非受控组件
    概述React中的受控组件和非受控组件都是针对于表单数据而言的。React推荐使用受控组件来处理表单数据。在受控组件中,表单数据由React组件的state管理。在非受控组......
  • Chrome 浏览器性能优化 Web API All In One
    Chrome浏览器性能优化WebAPIAllInOnehttps://caniuse.com/?search=SchedulerAPIChrome/Edge/FireFox支持✅Safari不支持❌PrioritizedTaskSchedul......
  • 是什么让.NET7的Min和Max方法性能暴增了45倍?
    简介在之前的一篇文章.NET性能系列文章一:.NET7的性能改进中我们聊到Linq中的Min()和Max()方法.NET7比.NET6有高达45倍的性能提升,当时Benchmark代码和结果如下所示:[Params......
  • AMD Xilinx MPSoC DFX 设计
    草稿目录总结概述OverviewDFXPetaLinux编译DFXfullbit加载DFXpartialbit加载其它测试环境工具测试单板参考文档总结概述OverviewDFXPetaLinux编译DFXful......
  • cookie
    cookie安全securehttpshttpOnly预防xssdocument.cookie×sameSite预防csrfstrict:cookie只发送给它的来源站点默认:laxcookieName前缀_Host-(与secure属性一起......
  • 如何用界面组件DevExpress WPF创建Excel式的过滤功能?赶紧Get
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专......
  • 【HMS Core】定位服务逆地理编码问题
    ​关于华为HMS-定位服务非华为手机逆地理编码不可用的问题。背景:在非华为手机例如小米手机上集成华为定位服务的逆地理编码功能运行后,报错HMSSDK_ServiceErrorCodeAdapto......