DevExpress专注于为 .NET、JavaScript、VCL 等多种平台提供高性能 UI 控件、报表工具、数据可视化组件及开发框架产品覆盖桌面、Web、移动及跨平台应用开发领域。凭借稳定的性能、丰富的功能与优质的技术支持DevExpress 的解决方案已广泛应用于金融、制造、医疗、能源、政府及教育等行业帮助开发者更高效地构建现代化应用程序。DevExpress官方宣布全新 .NET PowerPoint Presentation API 库的 Community Tech PreviewCTP版现已发布需使用 v25.1.4 及以上版本该库旨在帮助您在 .NET 应用中创建、读取、编辑、转换、合并、拆分以及打印 Microsoft PowerPoint 文件。在本文中我将介绍该 CTP 版的关键功能分享产品架构的见解并演示如何通过代码构建一个演示文稿管理应用程序。注意DevExpress Presentation API 库目前为 Community Technology PreviewCTP版本。DevExpress新旧版本下载欢迎进QQ qun169725316Presentation API概览跨平台PowerPoint文件处理DevExpress Presentation API 构建于 .NET 之上开箱即用地支持广泛的平台与操作系统。无论您在开发传统桌面应用、Web 后端还是跨平台解决方案都可以无缝集成 PowerPoint 文件处理能力无需依赖 Microsoft Office 或 PowerPoint 的安装环境。支持的框架、操作系统和环境包括NET 8/9, .NET Framework 4.6.2Windows, Linux, macOSAzure, AWS, Docker支持的文件格式与文档元素当前版本v25.1.x的 PowerPoint Presentation API 库支持导入与保存 PPTX 格式演示文稿文件同时支持将文件打印或导出为 PDF。该库提供了一整套 API 和设置帮助您以编程方式创建管理演示文稿元素——包括幻灯片、幻灯片布局、母版幻灯片备注、备注母版形状、连接器、文本框、图片形状文本、段落、占位符项目符号和编号列表演示文稿页眉与页脚内置与自定义文档属性演示文稿视图属性代码示例 — 将演示文稿转换为 PDFusing DevExpress.Docs.Presentation; //... // Load a presentation Presentation presentation new Presentation(File.ReadAllBytes(mypresentation.pptx)); // Export to PDF presentation.ExportToPdf(new FileStream(D:\exported-document.pdf, FileMode.Create));核心功能 — 程序化管理演示文稿DevExpress Presentation API 让您能够以编程方式生成及组织演示内容支持以下使用场景添加、复制、重新排序、调整大小、隐藏或删除幻灯片创建、自定义及应用不同的幻灯片布局访问并更新幻灯片母版内容合并多个演示文稿或将幻灯片从一个文档复制到另一个文档将一个演示文稿按幻灯片拆分成多个演示文稿提取或指定特定段落、形状、幻灯片、演讲者备注或整个演示文稿的文本格式化文本、段落、形状及幻灯片背景管理演示文稿元数据代码示例 — 合并两个演示文稿using DevExpress.Docs.Presentation; //... // Load presentations Presentation presentation1 new Presentation(File.ReadAllBytes(presentation1.pptx)); Presentation presentation2 new Presentation(File.ReadAllBytes(presentation2.pptx)); // Merge presentation slides foreach (Slide slide in presentation2.Slides) { presentation1.Slides.Add(slide); } // Save the merged document to the PPTX file FileStream outputStream new FileStream(D:\merged_presentation.pptx, FileMode.Create); presentation.SaveDocument(outputStream);面向对象的文档模型与依赖接口型文档模型的其他 PowerPoint 处理库不同DevExpress Presentation API 库采用了具体的面向对象模型设计。这种架构选择旨在提供更清晰、更灵活且更便于开发者使用的体验。使用DevExpress Presentation API库您可以直接使用直观的类——Slide、Shape、TextParagraph等。在向表示中添加新元素之前可以初始化文档对象并配置所有必要的设置这为基于流的文档生成提供了一种自然和结构化的方法。此外您可以跨多个幻灯片和演示文稿重用文档元素和配置设置。例如您可以将相同的幻灯片添加到多个演示文稿中或者对多个幻灯片或形状应用相同的格式如下面的示例所示。// Create and apply the custom background to multiple slides in two different presentations SolidFill fill new SolidFill(Color.LightCyan); CustomSlideBackground background new CustomSlideBackground(fill); presentation1.Slides[0].Background background; presentation1.Slides[1].Background background; presentation2.Slides[0].Background background;该方法允许您用更少的代码对表示文档进行更改同时如果需要唯一的实例来防止意外更改可以创建文档元素和设置单独的复制。开始使用 PowerPoint Presentation API若要在项目中使用 DevExpress Presentation API请按以下步骤操作1. 从Nuget.org安装 DevExpress.Docs.Presentation NuGet 包版本 v25.1.4 及以上dotnet add package DevExpress.Docs.Presentation --version 25.1.4也可通过 DevExpress 本地或个人 NuGet 源安装Office File API组件2. 在项目文件中添加 DevExpress.Docs.Presentation 命名空间。3. 创建 Presentation 实例使用无参数构造函数来新建一个带有一个空白幻灯片的演示文稿使用字节数组或流参数的构造函数来加载已有的 PPTX 文件。4. 使用 API 构建或修改演示文稿生成内容、设置格式、更新元数据、重新组织幻灯片等。5. 生成输出使用 Presentation.SaveDocument 保存为 PPTX使用 Presentation.ExportToPdf 生成 PDF使用 Presentation.Print 打印文档。代码示例 — 从零创建新演示文稿using DevExpress.Docs.Presentation; //... // Create a presentation with a single empty slide Presentation presentation new Presentation(); // Configure Slide Master SlideMaster slideMaster presentation.SlideMasters[0]; slideMaster.Background new CustomSlideBackground(new SolidFill(Color.FromArgb(194, 228, 249))); // Add a new slide with content presentation.Slides.Clear(); Slide slide1 new Slide(slideMaster.Layouts.Get(SlideLayoutType.Title)); foreach (Shape shape in slide1.Shapes) { if (shape.PlaceholderSettings.Type is PlaceholderType.CenteredTitle) { shape.TextArea new TextArea(Daily Testing Status Report); } if (shape.PlaceholderSettings.Type is PlaceholderType.Subtitle) { shape.TextArea new TextArea(${DateTime.Now: dddd, MMMM d, yyyy}); } } presentation.Slides.Add(slide1); // Save Presentation to PPTX FileStream outputStream new FileStream(D:\mypresentation.pptx, FileMode.Create); presentation.SaveDocument(outputStream);