在Adobe DC Pro中,您可以选择将pdf导出到excel 2003电子表格,方法是首先转到“导出PDF”,然后选择“ XML Spreadsheet 2003”,最后选择“为每个页面创建工作表”。 ”
我在excel vba中找不到执行此操作的任何代码。
我的问题是,如何使excel通过VBA完成此选项?只是将其另存为SaveAS FileFormat:= XlFileFormat.xlXMLSpreadsheet只会使其成为xml电子表格,而不是Adobe Pro所创建的“为每个页面创建工作表”。
谢谢
答案 0 :(得分:0)
您可以使用Adobe Acrobat Pro随附的 Adobe Acrobat 10.0类型库参考来实现。
以下是示例:
此代码将打开一个PDF文件,并将每个PDF页面分配给各个工作表。
Option Explicit
Sub PDF_To_Excel()
Dim PDF_ As Acrobat.AcroPDDoc
Dim Hilight_Text As Acrobat.AcroHiliteList
Dim PDF_Page As Acrobat.AcroPDPage
Dim Page_Text As Acrobat.AcroPDTextSelect
Dim ws As Worksheet
Dim Count_Page As Long
Dim i As Long, j As Long, k As Long
Dim PDF_Text_Str As String
Dim Hold_Txt As Variant
Set PDF_ = New Acrobat.AcroPDDoc
Set Hilight_Text = New Acrobat.AcroHiliteList
Hilight_Text.Add 0, 32767
With PDF_
.Open "C:\ED5049PX2.pdf"
Count_Page = .GetNumPages
For i = 1 To Count_Page
PDF_Text_Str = ""
Set PDF_Page = .AcquirePage(i - 1)
Set Page_Text = PDF_Page.CreateWordHilite(Hilight_Text)
If Not Page_Text Is Nothing Then
With Page_Text
For j = 0 To .GetNumText - 1
PDF_Text_Str = PDF_Text_Str & .GetText(j)
Next j
End With
End If
Set ws = Worksheets.Add(, Worksheets(Sheets.Count))
With ws
.Name = "Page-" & i
If PDF_Text_Str <> "" Then
Hold_Txt = Split(PDF_Text_Str, vbCrLf)
For k = 0 To UBound(Hold_Txt)
PDF_Text_Str = CStr(Hold_Txt(k))
If Left(PDF_Text_Str, 1) = "=" Then PDF_Text_Str = "'" & PDF_Text_Str
.Cells(k + 1, 1).Value = PDF_Text_Str
Next k
Else
.Cells(1, 1).Value = "No text found in page " & i
End If
.Cells.Select
.Cells.EntireColumn.AutoFit
End With
Next
.Close
End With
MsgBox ("Done")
End Sub
答案 1 :(得分:0)
我仍然对Page_Text Nothing有问题。即使我打开了pdf文件,似乎也看不到Page_Text。这是代码:
.Open "C:\User\test.pdf"
Count_Page=.GetNumPages
For I=1 to Count_Page
PDF_Text_Str=""
Set PDF_Page=.AcquirePage(i-1)
Set Page_Text=PDF_Page.CreateWordHilite(Hilight_Text)
If Not Page_Text is Nothing then
With Page_Text
For j=0 to .GetNumText -1
PDF_Text_Str=PDF_Text_Str & .GetText(j)
Next j
End With
End if
谢谢