如何使用 C# 在演示文稿中隐藏幻灯片

在这篇简单的文章中,我们将展示如何使用 C#** 在 Presentation 中隐藏幻灯片,而不依赖于 PowerPoint。您不需要任何第三方软件或 Interop 库来在 C# 中隐藏 PPTX 幻灯片。该应用程序很有用,可以在 Linux、Windows 或 macOS 内的任何 .NET 配置环境中引用,以隐藏演示文稿中所需的一张或多张幻灯片。

在 C# 中隐藏 PPTX 幻灯片的步骤

  1. 设置您的应用程序以从 NuGet 包管理器安装 Aspose.Slides for .NET
  2. 使用 Presentation 类加载源演示文稿以隐藏演示文稿中的幻灯片
  3. 访问演示文稿幻灯片集合中的第二张幻灯片,并通过设置 Slide.Hidden 属性隐藏幻灯片
  4. 将带有隐藏幻灯片的演示文稿保存在磁盘上

通过在 C# 中使用上述步骤,可以轻松地在所需的演示文稿中隐藏 PPTX 幻灯片。该过程首先使用 Presentation 类的实例从磁盘加载源演示文稿文件。然后将访问演示幻灯片集合中所需的一张或多张幻灯片,并将 Slide.Hidden 属性设置为 true 将隐藏选定的一张或多张幻灯片。最后,带有隐藏幻灯片的演示文稿将保存在磁盘上。

在 C# 中隐藏演示文稿中的幻灯片的代码

using Aspose.Slides;
namespace TestSlides
{
public class HideSlides
{
public static void SlideHiding()
{
string filesPath = @"/Users/Documents/KnowledgeBase/TestData/";
//Set the API license to hide the slide inside the presentation
License license = new License();
license.SetLicense(filesPath + "Conholdate.Total.Product.Family.lic");
//Access an exisiting presentation to access and hide the desired slide/s
Presentation SrcPresentation = new Presentation(filesPath+"Source.pptx");
//Access the 2nd slide inside the presentation
ISlide slide = SrcPresentation.Slides[1];
// Hide the selected slide
slide.Hidden = true;
//Save the presentation with a hidden slide/s
SrcPresentation.Save(filesPath + "PresWithHiddenSlide.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
}
}

上面的示例代码使用非常简单的 API 接口轻松在 C# 中隐藏 PPTX 中的幻灯片。您可以访问所需数量的多张幻灯片,甚至可以在您的应用程序中为每张幻灯片单独使用相同的属性来隐藏它们。最后,您可以根据您的应用程序要求,将演示文稿以 PPT、PPTX 或 ODP 格式保存在磁盘上或内存流中。

本主题涉及如何在 C# 中隐藏演示文稿中的幻灯片。如果您有兴趣了解如何在演示幻灯片中插入 SVG 图像,请参阅 如何使用 C# 将 SVG 转换为演示文稿 上的文章。

 简体中文