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

时间:2026-02-16 19:42: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幻灯片中的批注内容

© 2026 一点资料
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com