以编程方式从 PowerPoint 演示文稿中提取嵌入的文件 [英] Programmatically extract embedded file from PowerPoint presentation

查看:59
本文介绍了以编程方式从 PowerPoint 演示文稿中提取嵌入的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 VSTO PowerPoint 插件,它涉及录制和播放声音.我在最后一刻被要求允许用户选择播放声音的设备,就像 Skype 那样.

I am working on a VSTO PowerPoint add-in which involves recording and playing sounds. I was requested at the last minute to allow users to pick the device that will play the sound, like Skype does.

一般来说,我认为无法指定 PowerPoint 应该使用的设备,除非在控制面板中选择默认设备,但我无法以编程方式执行此操作.但是,我可以识别我的加载项录制的声音,因为它们作为 SoundEffect 嵌入到我标记的形状中.

In general, I don't think it is possible to specify what device PowerPoint should use, except by selecting the default device in the control panel, which I can't do programmatically. However I can recognize the sounds my add-in recorded because they are embedded as SoundEffect in Shapes that I tag.

我的问题是:是否可以直接访问 .wav 文件 - 类似于 SoundEffect.ImportFromFile,但在另一个方向?如果我能做到这一点,我就可以使用加载项代码(而不是 PowerPoint)打开和播放 .wav 文件.

My question is: is it possible to access the .wav file directly - something like the equivalent of SoundEffect.ImportFromFile, but in the other direction? If I could do that, I could open and play the .wav file using the add-in code, and not PowerPoint.

或者,有没有办法在演示文稿中添加和检索二进制文件作为嵌入内容?

Alternatively, is there a way to add and retrieve binary files as embedded content in a presentation?

我怀疑这是不可能的,但如果有人知道,我会在 StackOverflow 上找到那个人!

I suspect this is not possible, but that if someone knew, I would find that person on StackOverflow!

推荐答案

两者皆有可能.

  1. 从 PPTX 中提取 WAV:所有嵌入的媒体都在 .pptx\ppt\media 文件夹中(将 .pptx 重命名为 .zip,解压并导航到 \ppt\media).它们通常按照添加和/或处理的顺序依次编号.叙述,AFAIK,总是嵌入的,从不链接.问题将是确定要提取的确切内容 - 在添加到 pptx 时可以通过向其添加标签或其他唯一标识符来处理.提取它的方法是使用 Open XML SDK(或直接使用 System.IO.Packaging)并打开当前演示文稿的内存副本,在文件夹中找到您的 .wav(我使用 Linq-to-XML找到我需要的内容)并将其读入内存流,以便写入磁盘进行播放,或者如果您的加载项可以从内存流中播放,那就更好了.

  1. Extract WAVs from PPTX: All embedded media are in the .pptx\ppt\media folder (rename .pptx to .zip, unzip and nav to \ppt\media). They are usually sequentially numbered in the order they were added and/or processed. Narration, AFAIK, is always embedded and never linked. The problem will be identifying the exact one to extract - that may be taken care by adding a tag or other unique identifier to it when adding to the pptx. The way to extract it is to use the Open XML SDK (or just System.IO.Packaging directly) and open an in-memory copy of the current presentation, locate your .wav in the folder (I use Linq-to-XML to find what I need) and read that into a memory stream for either writing to disk to play or if your add-in can play from a memory stream, even better.

PPTX 中的二进制类型:任何东西都可以进入 Open XML 文档,但关键是让它留在那里.有关详细信息,请参阅此答案 - 是否可以将一些数据添加到 Word 文档中?.

Binary types in PPTX: Anything can go into an Open XML document, but it's making it stay there that is the key. See this answer for details - Is it possible to add some data to a Word document?.

这篇关于以编程方式从 PowerPoint 演示文稿中提取嵌入的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆