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

How to read a PowerPoint document and store its slides into Slide objects?

如何使用 C# 读取 PowerPoint 文档并将其幻灯片存储到 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");  

那么如何获取例如第一张幻灯片并将其保存到 object/variable Slide first_slide?

Presentation 对象有一个幻灯片集合,您可以将其编入索引。

我使用的是 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