一些Powerpoint演示文稿包含嵌入的电影。 如何使用C#(VSTO或Oficce COM Api)从演示文稿中导出电影(或获取电影文件路径)?
一些Powerpoint演示文稿包含嵌入的电影。 如何使用C#(VSTO或Oficce COM Api)从演示文稿中导出电影(或获取电影文件路径)?
不要忘记添加对PowerPoint COM API的引用(Microsoft PowerPoint 12.0 Object Library)。
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
private void button1_Click(object sender, EventArgs e)
{
PowerPoint.Application app = new PowerPoint.Application();
app.Visible = Office.MsoTriState.msoTrue;
//open powerpoint file in your hard drive
app.Presentations.Open(@"e:\my tests\hello world.pptx");
foreach (PowerPoint.Slide slide in app.ActivePresentation.Slides)
{
PowerPoint.Shapes slideShapes = slide.Shapes;
foreach (PowerPoint.Shape shape in slideShapes)
{
if (shape.Type == Office.MsoShapeType.msoMedia &&
shape.MediaType == PowerPoint.PpMediaType.ppMediaTypeMovie)
{
//LinkFormat.SourceFullName contains the movie path
//get the path like this
listBox1.Items.Add(shape.LinkFormat.SourceFullName);
//or use System.IO.File.Copy(shape.LinkFormat.SourceFullName, SOME_DESTINATION) to export them
}
}
}
}