如何以自动方式将 OLEObject 的内容保存为文件?
我正在向 powerpoint 幻灯片添加一些不同的文件类型。这些类型包括 mp4、zip、swf 和其他格式。我并不是在寻找播放这些文件类型的方法;而是在寻找一种方法来播放这些文件类型。但是,我想在 powerpoint preso 中存储和检索文件。
我通过执行以下操作成功存储了这些不同的文件类型:
currentSlide.Shapes.AddOLEObject(0, 0, -1, -1, "", this.filePath);
我还可以通过右键单击对象 -> 来手动检索它们。选择编辑包 ->文件->保存内容。
我希望复制或使用此功能将 OLEObject 的内容保存回其原始状态和我指定的路径。我有办法找到该形状,并且我认为该对象包含以下内容:我只是不知道现在该怎么办。有想法吗?谢谢。
哦,我正在使用 Office 2010,如果这有什么不同的话。
I am adding a few different file types to slides in powerpoint. These types include mp4, zip, swf, and other formats. I am not looking for a way to play these file types back; however, I'd like to store and retrieve files from within a powerpoint preso.
I've successfully stored these various file types by doing the following:
currentSlide.Shapes.AddOLEObject(0, 0, -1, -1, "", this.filePath);
I can also retrieve them manually by Right Clicking the Object -> Selecting Edit Package -> File -> Save Content.
I am looking to replicate or use this functionality to save the contents of the OLEObject back to its original state and to a path I specify. I have a way to find that shape and I think this object contains the contents: slideShape.OLEFormat.Object
I just don't know what to do now. Ideas? Thanks.
Oh I am using office 2010, if that makes any sort of difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以,我知道现在已经晚了;不过,我知道其他人一定也有类似的问题。
我就这个问题联系了微软,他们花了大约一个月的时间,但他们终于给了我答案。我有一个 解决方案的 zip。它相当广泛,请查看下面的简单源代码。
首先是一些说明:
1) 创建 PowerPoint 演示文稿并在其中嵌入一些文件(视频、mp3、zip 等)
2) 将文件保存到以下位置 C:\Temp\Temp.pptx
3)关闭文件
4) 在“C:\Temp”下创建文件夹“GenerateFiles”
5) 打开应用程序并运行它。
所以唯一的缺点是 PPTX 文件必须关闭。话虽如此,人们也许能够将打开的 PPTX 文件复制到其他位置,然后从该位置提取文件,而不是实际正在处理的 PPTX。然后把临时的删除就可以了。我们会看到。这已经是该解决方案最接近的结果了。
无需进一步告别:
So, I know this is late; however, I know others must have similar questions.
I contacted Microsoft about this issue and it took them around a month or so, but they finally got me an answer. I have a zip of the solution. It is fairly extensive, look below for just plain source code.
First some instructions:
1) Create a PowerPoint presentation and embed some files in it (Video, mp3, zip etc)
2) Save the file to the following location C:\Temp\Temp.pptx
3) Close the file
4) Create a folder “GeneratedFiles” under “C:\Temp”
5) Open the application and run it.
So the only downside is that the PPTX file must be closed. That being said, one might be able to copy the open PPTX file elsewhere and then extracted the files from that location rather than the PPTX that is actually being worked on. Then just delete the temporary one. We will see. This is as close as this solution gets though.
Without further adieu:
对象
slideShape.OLEFormat.Object
应支持IPersistFile
或IPersistStream
。如果是这样,您可以轻松地将其写入您选择的文件。为此,您需要使用 OLE 类型库来允许 VB 理解 IPersistFile 接口。从此页面下载 OLELIB.TLB,安装它,然后添加对 PPTX 的引用:
IPersistFile::Save
的文档:用法示例:
The object
slideShape.OLEFormat.Object
should supportIPersistFile
orIPersistStream
. If it does, you can readily cause it to write to a file of your choice. To do this you need a to use the OLE type library to allow VB to understand the IPersistFile interface.Download OLELIB.TLB from this page, install it, and add a reference to your PPTX:
Documentation for
IPersistFile::Save
:Example useage:
您可以通过从 .NET 或 c# 调用 PowerShell 来完成此操作。
上面的脚本取自此 文章。
这个 文章展示了如何从.NET调用它
href="http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C" rel="nofollow">文章展示了如何从c# Hope 这有帮助。
You can do that by calling PowerShell either from .NET or c#.
The above script was taken from this article.
This article shows how to call it from .NET
This article shows how to call it from c#
Hope this helps.