如何阅读PowerPoint文档并将其幻灯片存储到Slide对象中?

时间:2015-05-28 14:53:53

标签: c# powerpoint

如何阅读PowerPoint文档并使用C#将幻灯片存储到Slide对象中?

因此,如果我运行此代码并加载ppt文件:

Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application();  
Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;  
Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(@"D:\Peak Sourcing\Work\ppt_test\presenting.ppt");  

那么如何获得例如第一张幻灯片并将其保存到对象/变量Slide first_slide

2 个答案:

答案 0 :(得分:0)

Presentation对象有一个可以索引的Slides集合。

答案 1 :(得分:0)

我使用的是VBA,而不是C#,因此无法直接提供可用的代码示例,但这里大概如何在VBA中执行此操作:

Sub Example()

Dim oPres As Presentation
Dim oSl As Slide
Dim sFileName As String
Dim aSlides() As Slide

sFileName = "c:\somefolder\mypres.pptx"

' Open the presentation
Set oPres = Presentations.Open(sFileName)

' Prepare an array to hold slide objects
ReDim aSlides(1 To oPres.Slides.Count)

' Add each slide in the presentation to the array
For Each oSl In oPres.Slides
    Set aSlides(oSl.SlideIndex) = oSl
Next

' Now you have an array of slides
' Do what you will with it

End Sub