这个小话题主要关注如何访问C#中的Presentation属性,按照信息配置环境和一步一步的可运行示例代码。 在 C# 中读取 PPTX 文档属性的代码示例非常简单,可用于在 Windows、Linux 或 macOS 中运行的任何 .NET 支持的应用程序中。
在 C# 中读取 PPTX 文档属性的步骤
- 设置环境以添加 Aspose.Slides for .NET 以读取演示文稿属性
- 创建 IPresentationInfo 类的实例以从演示工厂访问演示信息集合
- 使用 IDocumentProperties 对象从演示信息实例访问演示文档属性
- 访问和打印演示文稿的文档属性
通过遵循 C# Presentation 文档属性 中的上述步骤,可以使用简单的 API 接口访问和操作。该过程从使用静态 PresentationFactory 类从演示工厂访问演示信息开始,您实际上不需要在此过程中将演示加载到 DOM 中。然后,通过使用 IDocumentProperties 的实例,可以在控制台中访问和显示属性。但是,您可以根据需要读取或写入访问的文档属性。
在 C# 中读取表示属性的代码
using System; | |
using Aspose.Slides; | |
namespace TestSlides | |
{ | |
public class AccessDocumentProperties | |
{ | |
public static void ReadDocumentProperties() | |
{ | |
String path = "/Users/Documents/TestData/"; | |
// Load the license file to access the presentation properties | |
Aspose.Slides.License docProplic = new Aspose.Slides.License(); | |
docProplic.SetLicense(path + "Conholdate.Total.Product.Family.lic"); | |
// Access the IPresentationInfo object to access the presentation factory | |
IPresentationInfo presInfo = PresentationFactory.Instance.GetPresentationInfo(path + "NewPresentation.pptx"); | |
// Access the presentation document properties | |
IDocumentProperties props = presInfo.ReadDocumentProperties(); | |
// Access and print the presentation document properties | |
Console.WriteLine($"CreatedTime : {props.CreatedTime}"); | |
Console.WriteLine($"Subject : {props.Subject}"); | |
Console.WriteLine($"Title : {props.Title}"); | |
Console.WriteLine($"Author : {props.Author}"); | |
Console.WriteLine($"Comments : {props.Comments}"); | |
Console.WriteLine($"RevisionNumber : {props.RevisionNumber}"); | |
} | |
} | |
} |
在演示代码的帮助下,可以使用非常简单的 API 调用读取 C# 中的表示属性。使用 PresentationFactory 类访问演示文稿文档属性时,内存占用非常小,因为整个演示文稿并未加载到文档对象模型中。 DocumentProperties 类不仅允许您访问和修改预定义的表示属性,还可以添加和访问自定义文档属性。
这个简单的教程需要如何使用 C# 读取演示属性。如果您有兴趣了解签署演示文稿的过程,请参阅 如何使用 C# 在 PowerPoint 中插入签名 上的文章。