C# 读取PPT幻灯片中的批注内容
此经验将介绍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#代码示例(供参考)
1、测试文件如下:
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、完成代码后,调试运行程序,生成文档,如下是批注读取结果: