Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

vba - Programmatically extract embedded file from PowerPoint presentation

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.

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.

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.

[Edit: by directly, I mean "without having to save the presentation under a different format"]

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Both are possible.

  1. Extract WAVs from PPTX: All embedded media are in the .pptxpptmedia folder (rename .pptx to .zip, unzip and nav to pptmedia). 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.

  2. 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?.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...