将表格从pdf导出到excel
本文关键字:excel pdf 表格 | 更新日期: 2023-09-27 18:04:17
如何通过c#编程仅将表内容导出到excel文件?我目前正在使用PDFNET SDK从pdf中提取所有内容,但无法将表读取为表格结构
我知道我没有使用过这个产品的SDK,但是我使用过独立的产品。它将PDF的内容读入电子表格(有许多导出选项)。
产品为OmniPage by Nuance http://australia.nuance.com/for-business/by-product/omnipage/index.htm
有一个免费的SDK。
使用bytescount PDF Extractor SDK,我们可以像下面这样提取整个页面,
CSVExtractor extractor = new CSVExtractor();
extractor.RegistrationName = "demo";
extractor.RegistrationKey = "demo";
TableDetector tdetector = new TableDetector();
tdetector.RegistrationKey = "demo";
tdetector.RegistrationName = "demo";
// Load the document
extractor.LoadDocumentFromFile("C:''sample.pdf");
tdetector.LoadDocumentFromFile("C:''sample.pdf");
int pageCount = tdetector.GetPageCount();
for (int i = 1; i <= pageCount; i++)
{
int j = 1;
do
{
extractor.SetExtractionArea(tdetector.GetPageRect_Left(i),
tdetector.GetPageRect_Top(i),
tdetector.GetPageRect_Width(i),
tdetector.GetPageRect_Height(i)
);
// and finally save the table into CSV file
extractor.SavePageCSVToFile(i, "C:''page-" + i + "-table-" + j + ".csv");
j++;
} while (tdetector.FindNextTable()); // search next table
}
既然是旧帖,希望对大家有所帮助
上面的答案(John)管用,真的很有用。
但是我使用bytescount PDF extracator SDK工具而不是使用代码。
顺便说一下,这个工具会在一个excel文件中生成很多表格。
您可以在excel中使用下面的代码生成一个工作表。
Sub ConvertAsOne()
Application.ScreenUpdating = False
For j = 1 To Sheets.Count
If Sheets(j).Name <> ActiveSheet.Name Then
X = Range("A65536").End(xlUp).Row + 1
Sheets(j).UsedRange.Copy Cells(X, 1)
End If
Next
Range("B1").Select
Application.ScreenUpdating = True
MsgBox "succeed!", vbInformation, "note"
End Sub