C# 读取PPT幻灯片中的批注内容

2025-10-23 00:25:15

1、在E-iceblue官爬瞧网或者Nuget网站上下载Free Spire.Presentation for .NET的安装激耻篇包后,注意在编辑代码时,添加引用Spire.Presentation.dll到程序。dll文耕言件可在安装路径下的Bin文件夹中获取。

C# 读取PPT幻灯片中的批注内容

1、测试文件如下:

C# 读取PPT幻灯片中的批注内容

2、using System;

using System.Text;

using Spire.Presentation;

using System.IO;

namespace ExtractTextFromComment_PPT

{

    class Program

    {

        static void Main(string[] args)

        {

            //实例化一个Presentation类,并加载文档

            Presentation ppt = new Presentation();

            ppt.LoadFromFile("sample.pptx");

            //创建一个StringBuilder对象

            StringBuilder str = new StringBuilder();

            //获取第一张幻灯片中的所有批注

            Comment[] comments = ppt.Slides[0].Comments;

            //遍历批注内容

            for (int i = 0; i < comments.Length; i++)

            {

                str.Append(comments[i].Text + "\r\n");

            }

            //将文本写入TXT

            File.WriteAllText("TextFromComment.txt", str.ToString());

            System.Diagnostics.Process.Start("TextFromComment.txt");

        }

    }

}

3、完成代码后,调试运行程序,生成文档,如下是批注读取结果:

C# 读取PPT幻灯片中的批注内容

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢