我有一个包含 100 张幻灯片的 Powerpoint 演示文稿 (.pptx) 文件。我想从其中取出所有文本并将其保存为纯文本文件。
我该怎么做?PowerPoint 似乎不允许您直接将其保存为 .txt 文件,而且我不想逐张浏览幻灯片来复制文本。
答案1
如果演示文稿中的所有文本在大纲视图中可见,那么您应该能够执行文件 | 另存为 | 选择大纲 (RTF)。
否则,您将需要一些 VBA。我的 PowerPoint FAQ 网站上有几个示例:
将文本导出到文本文件,从 PowerPoint(Mac 或 PC)中提取文本:
它将笔记页上每个形状的文本保存到与 PowerPoint 演示文稿本身位于同一文件夹中的名为 NotesText.TXT 的文件中。
Sub SaveNotesText()
Dim oPres As Presentation
Dim oSlides As Slides
Dim oSlide As Slide
Dim oShapes As Shapes
Dim oSh As Shape
Dim NotesText As String
Dim FileNum As Integer
Dim PathSep As String
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
For Each oSlide In oSlides
NotesText = NotesText & "Slide " & oSlide.SlideIndex & vbCrLf
Set oShapes = oSlide.NotesPage.Shapes
For Each oSh In oShapes
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
NotesText = NotesText & oSh.TextFrame.TextRange.Text
End If
End If
Next oSh
NotesText = NotesText & vbCrLf
Next oSlide
FileNum = FreeFile
Open oPres.Path & PathSep & "NotesText.TXT" For Output As FileNum
Print #FileNum, NotesText
Close FileNum
End Sub
这是 Kris Lander 编写的宏,它将导出演示文稿中每张幻灯片上的所有文本。对其进行了一些修改,使其可以在 Mac 上运行,并区分标题、副标题、正文和其他文本。
Sub ExportText()
Dim oPres As Presentation
Dim oSlides As Slides
Dim oSld As Slide 'Slide Object
Dim oShp As Shape 'Shape Object
Dim iFile As Integer 'File handle for output
iFile = FreeFile 'Get a free file number
Dim PathSep As String
Dim FileNum As Integer
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
FileNum = FreeFile
'Open output file
' NOTE: errors here if file hasn't been saved
Open oPres.Path & PathSep & "AllText.TXT" For Output As FileNum
For Each oSld In oSlides 'Loop thru each slide
For Each oShp In oSld.Shapes 'Loop thru each shape on slide
'Check to see if shape has a text frame and text
If oShp.HasTextFrame And oShp.TextFrame.HasText Then
If oShp.Type = msoPlaceholder Then
Select Case oShp.PlaceholderFormat.Type
Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderBody
Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderSubtitle
Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
Case Else
Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.TextRange
End Select
Else
Print #iFile, vbTab & oShp.TextFrame.TextRange
End If ' msoPlaceholder
End If ' Has text frame/Has text
Next oShp
Next oSld
'Close output file
Close #iFile
End Sub
这里我们有点棘手,要研究分组的文本。分组中的分组。如果太仔细看,你的头可能会开始疼。
Sub ExportText()
Dim oPres As Presentation
Dim oSlides As Slides
Dim oSld As Slide 'Slide Object
Dim oShp As Shape 'Shape Object
Dim iFile As Integer 'File handle for output
iFile = FreeFile 'Get a free file number
Dim PathSep As String
Dim FileNum As Integer
Dim sTempString As String
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
FileNum = FreeFile
'Open output file
' NOTE: errors here if file hasn't been saved
Open oPres.Path & PathSep & "AllText.TXT" For Output As FileNum
For Each oSld In oSlides 'Loop thru each slide
' Include the slide number (the number that will appear in slide's
' page number placeholder; you could also use SlideIndex
' for the ordinal number of the slide in the file
Print #iFile, "Slide:" & vbTab & cstr(oSld.SlideNumber)
For Each oShp In oSld.Shapes 'Loop thru each shape on slide
'Check to see if shape has a text frame and text
If oShp.HasTextFrame And oShp.TextFrame.HasText Then
If oShp.Type = msoPlaceholder Then
Select Case oShp.PlaceholderFormat.Type
Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderBody
Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderSubtitle
Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
Case Else
Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.TextRange
End Select
Else
Print #iFile, vbTab & oShp.TextFrame.TextRange
End If ' msoPlaceholder
Else ' it doesn't have a textframe - it might be a group that contains text so:
If oShp.Type = msoGroup Then
sTempString = TextFromGroupShape(oShp)
If Len(sTempString) > 0 Then
Print #iFile, sTempString
End If
End If
End If ' Has text frame/Has text
Next oShp
Next oSld
'Close output file
Close #iFile
End Sub
Function TextFromGroupShape(oSh As Shape) As String
' Returns the text from the shapes in a group
' and recursively, text within shapes within groups within groups etc.
Dim oGpSh As Shape
Dim sTempText As String
If oSh.Type = msoGroup Then
For Each oGpSh In oSh.GroupItems
With oGpSh
If .Type = msoGroup Then
sTempText = sTempText & TextFromGroupShape(oGpSh)
Else
If .HasTextFrame Then
If .TextFrame.HasText Then
sTempText = sTempText & "(Gp:) " & .TextFrame.TextRange.Text & vbCrLf
End If
End If
End If
End With
Next
End If
TextFromGroupShape = sTempText
NormalExit:
Exit Function
Errorhandler:
Resume Next
End Function
答案2
答案3
从您的 PDF 阅读器中导出为 PDF,复制并粘贴(CTRL+A、CTRL+C)。
如果你需要一些格式化,可以通过以下方式导出 PDFpdf转文本带参数-layout
答案4
我认为最简单的方法是将 PPT 文档上传到 Google Drive,在 Google Slides 中打开它,然后选择文件>下载>纯文本。
然后您可以在 Word 或 Google Docs 中打开它。