跳過到頁腳內容
EXCEL 工具

如何在 C# 中查看 PowerPoint 文件

使用 C# 和 IronPPT 處理 PowerPoint

IronPPT

雖然目前不支持在 C# 中構建 PowerPoint 檢視器,但開發人員仍可使用強大的工具來程式化操作簡報檔案。 IronPPT 是一個現代化的 .NET 函式庫,可幫助開發人員 使用 C# 創建、讀取和編輯 PowerPoint 檔案 (.pptx),無需微軟 Office 或 COM Interop。

role="alert">介紹 IronPPT:Iron Software 提供的 .NET PowerPoint 函式庫
IronPPT 無縫載入和保存 PPTX 檔案 - 無需微軟 Office。這是自動化幻燈片、文字、形狀和圖像在任何 .NET 應用中的理想選擇。立即開始使用 IronPPT!

如果您的目標是動態生成幻燈片組、操作現有內容或將 PowerPoint 自動化流程整合到您的 .NET 工作流程中,IronPPT 專為通過清晰直觀的 API 簡化這些過程而設計。

讓我們仔細看看您能夠透過 IronPPT 完成的操作:

IronPPT 的主要功能

IronPPT 著重於賦予開發人員從程式碼中處理 PowerPoint 簡報的能力。 以下是目前支持的核心功能:

  • 從頭創建 PowerPoint 簡報 IronPPT 允許您程式化生成 .pptx 檔案,定義幻燈片佈局、添加文本框、插入圖像和形狀以及定制格式。 您可以根據數據或用戶輸入動態構建精緻的幻燈片,非常適合報告、模板化和內容自動化。
  • 編輯現有 .pptx 檔案 您可以打開和修改 PowerPoint 檔案以更新文本、替換或插入圖像、重排幻燈片、更改格式或添加新內容。 這使得它非常適合批處理或將自動化更新整合到您的業務工作流中。
  • 訪問並操作幻燈片元素 IronPPT 讓您對幻燈片組件擁有完全控制權。 您可以:
  • 添加或刪除文本框和段落
  • 修改字體樣式、對齊和間距
  • 使用可配置屬性插入並設置形狀樣式
  • 從文件或流中載入圖像並精確定位
  • 讀取幻燈片內容 除了寫入幻燈片,IronPPT 還可讀取和提取內容 從現有的 .pptx 檔案中。 這包括幻燈片標題、段落文本、圖像和形狀,允許您重置或分析簡報數據。
  • 不需微軟 Office IronPPT 完全獨立於微軟 PowerPoint 運行。 不需要辦公室安裝或 Interop 函式庫,這使得它在伺服環境、CI/CD 管道、雲應用和跨平台項目中構建部署成為理想選擇。

何時使用 IronPPT

IronPPT 最適合需要做以下事情的 .NET 開發人員:

  • 自動創建簡報檔案
  • 程式化修改 .pptx 內容
  • 提取和分析幻燈片內容
  • 在無法提供 Office 的環境中工作

雖然 IronPPT 目前尚不支持匯出或查看簡報,但它依然是一個可靠的面向後端的 PowerPoint 生成和處理的未來化解決方案。

IronPPT VS Office Interop (對比表格)

Csharp Powerpoint Viewer Tutorial 4 related to IronPPT VS Office Interop (對比表格)

IronPPT 實施範例

現在我們已經更多了解 IronPPT 和它是如何工作的,那就來看看如何通過 IronPPT 創建一個包含標題、自定義形狀和圖像的新簡報文件。 雖然這個例子只是一個基本的演示了這些功能如何工作,您可以輕鬆實現它們來創建視覺獨特和信息豐富的 PowerPoint 簡報。

代碼示例

using IronPPT;
using IronPPT.Models;

var doc = new PresentationDocument();

// Add a title to the first slide
doc.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT!");

// Adding an image to the first slide
Image image = new Image();
image.LoadFromFile("ironppt.png");
var newImage = doc.AddImage(image, 0);
newImage.Position = (100, 300);
newImage.Width = 500;
newImage.Height = 200;

// Adding a new slide with a custom shape
Slide slide = new Slide();
doc.AddSlide(slide);

Shape shape = new Shape();
shape.Type = IronPPT.Enums.ShapeType.Cloud;
shape.Width =  200;
shape.Position = (200, 200);
shape.FillColor = new Color(255, 0, 0); // Red color
shape.OutlineColor = Color.Black; // Black outline
doc.Slides[1].AddShape(shape);

doc.Save("test.pptx");
using IronPPT;
using IronPPT.Models;

var doc = new PresentationDocument();

// Add a title to the first slide
doc.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT!");

// Adding an image to the first slide
Image image = new Image();
image.LoadFromFile("ironppt.png");
var newImage = doc.AddImage(image, 0);
newImage.Position = (100, 300);
newImage.Width = 500;
newImage.Height = 200;

// Adding a new slide with a custom shape
Slide slide = new Slide();
doc.AddSlide(slide);

Shape shape = new Shape();
shape.Type = IronPPT.Enums.ShapeType.Cloud;
shape.Width =  200;
shape.Position = (200, 200);
shape.FillColor = new Color(255, 0, 0); // Red color
shape.OutlineColor = Color.Black; // Black outline
doc.Slides[1].AddShape(shape);

doc.Save("test.pptx");
Imports IronPPT
Imports IronPPT.Models

Private doc = New PresentationDocument()

' Add a title to the first slide
doc.Slides(0).TextBoxes(0).AddText("Welcome to IronPPT!")

' Adding an image to the first slide
Dim image As New Image()
image.LoadFromFile("ironppt.png")
Dim newImage = doc.AddImage(image, 0)
newImage.Position = (100, 300)
newImage.Width = 500
newImage.Height = 200

' Adding a new slide with a custom shape
Dim slide As New Slide()
doc.AddSlide(slide)

Dim shape As New Shape()
shape.Type = IronPPT.Enums.ShapeType.Cloud
shape.Width = 200
shape.Position = (200, 200)
shape.FillColor = New Color(255, 0, 0) ' Red color
shape.OutlineColor = Color.Black ' Black outline
doc.Slides(1).AddShape(shape)

doc.Save("test.pptx")
$vbLabelText   $csharpLabel

輸出

Csharp Powerpoint Viewer Tutorial 2 related to 輸出

IronPPT 許可證

Csharp Powerpoint Viewer Tutorial 5 related to IronPPT 許可證 IronPPT 提供商業許可證,並擁有不同級別,以最佳滿足您的需求。 從永久許可權,為您的項目提供按所需涵蓋的開發人員數量、項目和地點界定保護,到按月訂閱許可權,提供不想承諾年度訂閱的團隊的即用即付模式。

您可以使用免費試用版評估 IronPPT 不需風險,該試用版包括所有功能,輸出過程中會加上水印以供 在致力於生產許可證之前能夠完全測試並融入您現有的 .NET 工作流程。

Csharp Powerpoint Viewer Tutorial 1 related to IronPPT 許可證

總結:在 .NET 中構建更智能的 PowerPoint 工作流

儘管 IronPPT 目前尚不支持實時渲染幻燈片或查看簡報,但它提供了強大的工具,可在您的 C# 應用中自動 PowerPoint 檔案創建、編輯與內容提取。 對於後端處理、動態幻燈片生成和無需 Office 的 .pptx 處理,IronPPT 是一個對開發者友好,可擴展的解決方案,融入現代 .NET 項目中無縫隙。

如果您已經準備好精簡您的 PowerPoint 工作流程和消除 Office 依賴性,立即開始免費試用 IronPPT

👉 下載 IronPPT 免費試用版

探索其功能,在您的真實世界環境中測試它,看看在 .NET 應用中帶入 PowerPoint 自動化有多簡單。

Jordi Bardia
軟體工程師
Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。