使用 C# .NET 在 PowerPoint 中閱讀添加更新和刪除幻燈片註釋

PowerPoint 演示文稿中的幻燈片註釋用於添加參考,供演示者在演示過程中回憶要點。這些註釋可以添加到 PowerPoint 演示文稿的每張幻燈片中。本文還介紹了以編程方式處理演示文稿中的幻燈片註釋的一些重要方面。

閱讀本文後,您將能夠:

使用 Aspose.Slides for .NET 處理幻燈片註釋

為了在 PowerPoint 中使用幻燈片註釋,我們將使用 Aspose.Slides for .NET - 一個強大的 PowerPoint 自動化 API,支持創建、更新、解析和轉換演示文稿文檔。您可以下載 API 或使用以下選項安裝它:

使用 NuGet 包管理器

在 PowerPoint C# .NET 中閱讀或更新幻燈片註釋

使用包管理器控制台

PM> Install-Package Aspose.Slides.NET

在 C# 中閱讀 PowerPoint 演示文稿中的幻燈片註釋

為了在PowerPoint中訪問幻燈片註釋,Aspose.Slides for .NET提供了INotesSlideManager接口。 INotesSlideManager 允許您訪問、閱讀、添加和更新幻燈片註釋。以下是從 PowerPoint 演示文稿中閱讀幻燈片註釋的步驟。

下面的代碼示例演示如何使用 C# 從 PowerPoint PPTX 中讀取幻燈片註釋。

// 加載 PowerPoint 演示文稿
Presentation presentation = new Presentation("presentation.pptx");
INotesSlideManager mgr = presentation.Slides[0].NotesSlideManager;
// 閱讀幻燈片註釋
INotesSlide note = mgr.NotesSlide;
Console.Write(note.NotesTextFrame.Text);

在 C# 中向 PowerPoint 幻燈片添加註釋

以下是向 PowerPoint 演示文稿中的特定幻燈片添加註釋的步驟。

  • 在 Presentation 對像中加載 PowerPoint 演示文稿。
  • 訪問特定幻燈片的 NotesSlideManager。
  • 使用 INotesSlide 界面添加新筆記。
  • 使用 Presentation.Save(String, SaveFormat) 方法保存演示文稿。

以下代碼示例演示如何使用 C# 將幻燈片註釋添加到 PowerPoint PPTX。

// 加載 PowerPoint 演示文稿
Presentation presentation = new Presentation("presentation.pptx");
INotesSlideManager mgr = presentation.Slides[0].NotesSlideManager;
// 添加新的幻燈片註釋
INotesSlide note = mgr.AddNotesSlide();
note.NotesTextFrame.Text = "new slide note";
// 保存演示文稿
presentation.Save("added-slide-notes.pptx", SaveFormat.Pptx);

使用 C# 更新 PowerPoint 演示文稿中的幻燈片註釋

為了更新特定演示幻燈片中的註釋,您將以與閱讀註釋相同的方式訪問 NotesSlide。訪問幻燈片註釋後,您可以使用 INotesSlide.NotesTextFrame.Text 屬性簡單地更新文本。完成後,使用 Presentation.Save(String, SaveFormat) 方法保存演示文稿文件。

以下代碼示例演示如何使用 C# 更新 PowerPoint 演示文稿中的幻燈片註釋。

// 加載 PowerPoint 演示文稿
Presentation presentation = new Presentation("presentation.pptx");
INotesSlideManager mgr = presentation.Slides[0].NotesSlideManager;
// 訪問幻燈片註釋
INotesSlide note = mgr.NotesSlide;
// 更新幻燈片備註的文本 
note.NotesTextFrame.Text = "this is updated note";
// 保存演示文稿
presentation.Save("updated-slide-notes.pptx", SaveFormat.Pptx);

使用 C# 刪除 PowerPoint 演示文稿中的幻燈片註釋

要從 PowerPoint 演示文稿中刪除幻燈片註釋,只需調用 INotesSlideManager.RemoveNotesSlide() 方法並保存演示文稿文件。以下代碼示例演示如何使用 C# 從 PowerPoint 演示文稿中刪除幻燈片註釋。

// 加載 PowerPoint 演示文稿
Presentation presentation = new Presentation("presentation.pptx");
INotesSlideManager mgr = presentation.Slides[0].NotesSlideManager;
// 刪除幻燈片備註
mgr.RemoveNotesSlide();
// 保存演示文稿
presentation.Save("removed-slide-notes.pptx", SaveFormat.Pptx);

也可以看看

免費試用 Aspose.Slides for .NET

您可以使用免費的 臨時許可證 試用 Aspose.Slides for .NET。