保存演示文稿 - C++ PowerPoint 库

本文解释了如何保存演示文稿。

Presentation 类包含演示文稿的内容。无论是从头创建演示文稿还是修改现有的,在完成后,您都希望保存演示文稿。使用 Aspose.Slides for C++,可以将演示文稿保存为 文件。本文解释了以不同方式保存演示文稿的方法:

将演示文稿保存到文件

通过调用 Presentation 类的 Save 方法将演示文稿保存到文件。只需将文件名和保存格式传递给 Save 方法。以下示例演示了如何使用 Aspose.Slides for C++ 保存演示文稿。

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveToFile_out.ppt";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//pres->get_ProtectionManager()->Encrypt(u"pass");
//...do some work here..
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

将演示文稿保存到流

通过将输出流传递给 Presentation 类的 Save 方法,可以将演示文稿保存到流中。可以将演示文稿保存到多种类型的流。下面的示例中,我们创建了一个新的演示文稿文件,在形状中添加文本,并将演示文稿保存到流中。

const String outPath = u"../out/Save_As_Stream_out.pptx";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
SharedPtr<IAutoShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->AddAutoShape(Aspose::Slides::ShapeType::Rectangle, 200, 200, 200, 200);
/// Load the video file to stream
System::SharedPtr<System::IO::Stream> stream = System::MakeObject<System::IO::FileStream>(outPath, System::IO::FileMode::Create);
pres->Save(stream, Aspose::Slides::Export::SaveFormat::Pptx);

使用预定义视图类型保存演示文稿

Aspose.Slides for C++ 提供了在 PowerPoint 中打开生成的演示文稿时设置视图类型的功能,通过 ViewProperties 类。 LastView 属性用于通过 ViewType 枚举器设置视图类型。

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveAsPredefinedViewType_out.ppt";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
pres->get_ViewProperties()->set_LastView(Aspose::Slides::ViewType::SlideMasterView);
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

将演示文稿保存为严格的 Office Open XML 格式

Aspose.Slides 允许您以严格的 Office Open XML 格式保存演示文稿。为此,它提供了 PptxOptions 类,您可以在保存演示文稿文件时设置 Conformance 属性。如果将其值设置为 Conformance.Iso29500_2008_Strict,则输出的演示文稿文件将以严格的 Office Open XML 格式保存。

以下示例代码创建一个演示文稿并将其保存为严格的 Office Open XML 格式。在调用演示文稿的 Save 方法时,PptxOptions 对象会传入,其中 Conformance 属性设置为 Conformance.Iso29500_2008_Strict

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveToStrictOpenXML_out.pptx";
//Instantiate Presentation object
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add an AutoShape of Rectangle type
SharedPtr<IAutoShape> ashp = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 150, 75, 150, 50);
//Setting options for strick XML
SharedPtr<PptxOptions> options = MakeObject<PptxOptions>();
options->set_Conformance(Conformance::Iso29500_2008_Strict);
//Save presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx, options);

以百分比保存进度更新

新的 IProgressCallback 接口已添加到 ISaveOptions 接口和 SaveOptions 抽象类中。 IProgressCallback 接口表示用于保存进度更新的回调对象,以百分比表示。

以下代码片段显示如何使用 IProgressCallback 接口:

const String templatePath = u"../templates/SamplePresentation.pptx";
const String outPath = u"../out/SamplePresentation_out.pptx";
auto presentation = System::MakeObject<Presentation>(templatePath);
System::SharedPtr<ISaveOptions> saveOptions = System::MakeObject<PdfOptions>();
System::SharedPtr<IProgressCallback> callBack = System::MakeObject<ExportProgressHandler>();
saveOptions->set_ProgressCallback(callBack);
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pdf, saveOptions);
class ExportProgressHandler : public IProgressCallback
{
public:
void Reporting(double progressValue)
{
System::Console::WriteLine(u"% completed", progressValue);
}
};