c# - 保存和自动保存 PowerPoint OpenXML PresentationDocuments

标签 c# powerpoint openxml openxml-sdk powerpoint-2007

我正在寻找有关保存 OpenXML 文档的一些建议,特别是 PresentationDocument。

在我的场景中,我直接从磁盘打开一个 PowerPoint .pptx 演示文稿,它充当模板。然后,我从各种其他 PowerPoint 演示文稿中添加(复制)幻灯片。对于每个单独的源演示文稿,我还添加了它的 MasterSlidePart 和 SlideLayoutPart。

问题 1: 当演示文稿需要保存时,是否可以发出一条命令来保存对 PresentationDocument 的所有更改?或者我是否必须手动保存每个新的或已更改的项目,例如:

        presentationDocument.PresentationPart.Presentation.Save();

        foreach (var slideMasterPart in presentationDocument.PresentationPart.SlideMasterParts)
        {
            slideMasterPart.SlideMaster.Save();
        }

问题 2: 打开 PresentationDocument 时,有一个“自动保存”选项似乎默认为“true”。任何人都可以准确解释自动保存的作用吗?

我读到的内容表明,在处理 PresentationDocument 时,这会将所有内容保存在 PresentationDocument 中。这是正确的吗?

如果是这样,我将需要设置 autosave=false,因为我需要自己控制保存,以便能够测试演示构建逻辑。

提前感谢您的回答。

史蒂夫

最佳答案

问题 1:如果您使用流打开文件并以这种方式进行修改,则无需显式调用其中任何一个保存调用。您只需调用 Dispose() presentationDocument 变量上的方法。文档说明要处理

Flushes and saves the content, closes the document, and releases all resources.

这将使您不必在演示文稿上调用保存或循环浏览每张单独的幻灯片。

问题 2: autosave 的文档陈述如下:

Gets the flag indicating whether the parts should be saved on disposing.

这让我相信,如果您希望在调用 Dispose() 方法时保存所有部分,您会希望将此值设置为 true。否则,您的更改可能无法保存。

关于c# - 保存和自动保存 PowerPoint OpenXML PresentationDocuments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7820471/

相关文章:

excel - 在 Excel 中使用 VBA 从 PowerPoint 模板创建新的 PowerPoint 演示文稿

VBA PowerPoint 在线指南和如何录制宏

c# - Openxml:使用自定义属性添加新行

Java docx4j 粗体文本

c# - 在包含的布局的 TextView 中添加点击监听器

c# - 使用 C# 在 asp.net 中更新语句

c# - 在从 C# 到 C 的 P/Invoke 调用期间编码输出指针

c# - MVC 6 中的 POCO Controller

javascript - 将图像从 Firefox 拖放到 Microsoft Powerpoint

c# - 使用 C# 和 OpenXML 设置缩放属性以适应 Excel