翻譯|行業(yè)資訊|編輯:龔雪|2025-08-22 10:42:34.497|閱讀 81 次
概述:本文將為大家介紹DevExpress近期全新發(fā)布得新一代PowerPoint Presentation API庫,歡迎下載最新版組件體驗(yàn)!
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DevExpress專注于為 .NET、JavaScript、VCL 等多種平臺提供高性能 UI 控件、報(bào)表工具、數(shù)據(jù)可視化組件及開發(fā)框架,產(chǎn)品覆蓋桌面、Web、移動及跨平臺應(yīng)用開發(fā)領(lǐng)域。憑借穩(wěn)定的性能、豐富的功能與優(yōu)質(zhì)的技術(shù)支持,DevExpress 的解決方案已廣泛應(yīng)用于金融、制造、醫(yī)療、能源、政府及教育等行業(yè),幫助開發(fā)者更高效地構(gòu)建現(xiàn)代化應(yīng)用程序。
DevExpress官方宣布全新 .NET PowerPoint Presentation API 庫的 Community Tech Preview(CTP)版現(xiàn)已發(fā)布(需使用 v25.1.4 及以上版本),該庫旨在幫助您在 .NET 應(yīng)用中創(chuàng)建、讀取、編輯、轉(zhuǎn)換、合并、拆分以及打印 Microsoft PowerPoint 文件。
在本文中,我將介紹該 CTP 版的關(guān)鍵功能,分享產(chǎn)品架構(gòu)的見解,并演示如何通過代碼構(gòu)建一個(gè)演示文稿管理應(yīng)用程序。
注意:DevExpress Presentation API 庫目前為 Community Technology Preview(CTP)版本。
DevExpress技術(shù)交流群11:749942875 歡迎一起進(jìn)群討論
DevExpress Presentation API 構(gòu)建于 .NET 之上,開箱即用地支持廣泛的平臺與操作系統(tǒng)。無論您在開發(fā)傳統(tǒng)桌面應(yīng)用、Web 后端,還是跨平臺解決方案,都可以無縫集成 PowerPoint 文件處理能力,無需依賴 Microsoft Office 或 PowerPoint 的安裝環(huán)境。
支持的框架、操作系統(tǒng)和環(huán)境包括:
當(dāng)前版本(v25.1.x)的 PowerPoint Presentation API 庫支持導(dǎo)入與保存 PPTX 格式演示文稿文件,同時(shí)支持將文件打印或?qū)С鰹?PDF。
該庫提供了一整套 API 和設(shè)置,幫助您以編程方式創(chuàng)建/管理演示文稿元素——包括:
代碼示例 — 將演示文稿轉(zhuǎn)換為 PDF
using 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 讓您能夠以編程方式生成及組織演示內(nèi)容,支持以下使用場景:
代碼示例 — 合并兩個(gè)演示文稿
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 庫采用了具體的面向?qū)ο竽P驮O(shè)計(jì)。這種架構(gòu)選擇旨在提供更清晰、更靈活且更便于開發(fā)者使用的體驗(yàn)。
使用DevExpress Presentation API庫,您可以直接使用直觀的類——Slide、Shape、TextParagraph等。在向表示中添加新元素之前,可以初始化文檔對象并配置所有必要的設(shè)置,這為基于流的文檔生成提供了一種自然和結(jié)構(gòu)化的方法。
此外,您可以跨多個(gè)幻燈片和演示文稿重用文檔元素和配置設(shè)置。例如,您可以將相同的幻燈片添加到多個(gè)演示文稿中,或者對多個(gè)幻燈片或形狀應(yīng)用相同的格式(如下面的示例所示)。
// 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;
該方法允許您用更少的代碼對表示文檔進(jìn)行更改,同時(shí)如果需要唯一的實(shí)例來防止意外更改,可以創(chuàng)建文檔元素和設(shè)置單獨(dú)的復(fù)制。
若要在項(xiàng)目中使用 DevExpress Presentation API,請按以下步驟操作:
1. 從 安裝 DevExpress.Docs.Presentation NuGet 包(版本 v25.1.4 及以上):
dotnet add package DevExpress.Docs.Presentation --version 25.1.4
(也可通過 DevExpress 本地或個(gè)人 NuGet 源安裝 Office File API 組件)
2. 在項(xiàng)目文件中添加 DevExpress.Docs.Presentation 命名空間。
3. 創(chuàng)建 Presentation 實(shí)例:
4. 使用 API 構(gòu)建或修改演示文稿(生成內(nèi)容、設(shè)置格式、更新元數(shù)據(jù)、重新組織幻燈片等)。
5. 生成輸出:
代碼示例 — 從零創(chuàng)建新演示文稿
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);
更多產(chǎn)品資訊及授權(quán),歡迎來電咨詢:023-68661681
慧都是?家?業(yè)數(shù)字化解決?案公司,專注于軟件、?油與?業(yè)領(lǐng)域,以深?的業(yè)務(wù)理解和?業(yè)經(jīng)驗(yàn),幫助企業(yè)實(shí)現(xiàn)智能化轉(zhuǎn)型與持續(xù)競爭優(yōu)勢。
慧都是DevExpress的中國區(qū)的合作伙伴,DevExpress作為用戶界面領(lǐng)域的優(yōu)秀產(chǎn)品,幫助企業(yè)高效構(gòu)建權(quán)限管理、數(shù)據(jù)可視化(如網(wǎng)格/圖表/儀表盤)、跨平臺系統(tǒng)(WinForms/ASP.NET/.NET MAUI)及行業(yè)定制解決方案,加速開發(fā)并強(qiáng)化交互體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)