如何使用PresentationDocument.open()for PowerPoint加载项打开已打开的演示文稿

本文关键字:文稿 加载项 PowerPoint PresentationDocument 何使用 open for | 更新日期: 2023-09-27 17:57:53

我有一个PowerPoint加载项,可以创建、修改和保存演示文稿。打开的演示文稿的特定选项应该使用Open XML存储在此演示文稿文件(.pptx)中,当我尝试这样做时,我会得到IOException:

**System.IO.IOException : The process cannot access the file 'test.pptx' because it is being used by another process.**

这是代码的一个片段:

**

using (PresentationDocument pptPackage = PresentationDocument.Open(fileName, true))
{
// add options to pptx file.
}

**

谢谢。

如何使用PresentationDocument.open()for PowerPoint加载项打开已打开的演示文稿

如果您只需要使用Open XML阅读打开的演示文稿,您可以这样做:

using (Stream stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (PresentationDocument pptPackage = PresentationDocument.Open(stream, false))
{
    // read pptx file.
}

但你不能用这种方式改变演示。