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

2025-06-04 13:04:20

此经验将介绍C#读取取幻灯片中的批注内容。

工具/原料

Free Spire.Presentation for .NET 3.3 (免费版)

Visual Studio

dll引用

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

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

C#代码示例(供参考)

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。
猜你喜欢