PDF是一種通用的文件格式,但它很難編輯。如果您想修改和計算PDF數據,將PDF轉換為Excel將是一個理想的解決方案。在本文中,您將了解如何使用Spire.PDF for .NET在 C# 和 VB.NET 中將 PDF 轉換為 Excel。
Spire.Doc?是一款專門對 Word 文檔進行操作的 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。?
E-iceblue?功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式(qun:767755948)
Spire.PDF for.net下載? ?Spire.PDF for java下載
安裝適用于 .NET 的 Spire.PDF
首先,您需要將 Spire.PDF for .NET 包中包含的 DLL 文件添加為 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
PM> Install-Package Spire.PDF
在 C# 和 VB.NET 中將 PDF 轉換為 Excel
以下是將 PDF 文檔轉換為 Excel 的步驟:
- 初始化PdfDocument類的實例。
- 使用PdfDocument.LoadFromFile(filePath)方法加載 PDF 文檔。
- 使用PdfDocument.SaveToFile(filePath, FileFormat.XLSX)方法將文檔保存到 Excel?。
[C#]
using Spire.Pdf; using Spire.Pdf.Conversion;namespace ConvertPdfToExcel { class Program { static void Main(string[] args) { //Initialize an instance of PdfDocument class PdfDocument pdf = new PdfDocument(); //Load the PDF document pdf.LoadFromFile("Sample.pdf");//Save the PDF document to XLSX pdf.SaveToFile("PdfToExcel.xlsx", FileFormat.XLSX); } } }
[VB.NET]
Imports Spire.Pdf Imports Spire.Pdf.ConversionNamespace ConvertPdfToExcel Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Initialize an instance of PdfDocument class Dim pdf As PdfDocument = New PdfDocument() 'Load the PDF document pdf.LoadFromFile("Sample.pdf")'Save the PDF document to XLSX pdf.SaveToFile("PdfToExcel.xlsx", FileFormat.XLSX) End Sub End Class End Namespace
使用 C# 和 VB.NET 將多頁 PDF 轉換為一張 Excel 工作表
以下是將多頁 PDF 轉換為一張 Excel 工作表的步驟:
- 初始化PdfDocument類的實例。
- 使用PdfDocument.LoadFromFile(filePath)方法加載 PDF 文檔。
- 初始化XlsxLineLayoutOptions類的實例,在類構造函數中,將第一個參數convertToMultipleSheet設置為false。
- 使用PdfDocument.ConvertOptions.SetPdfToXlsxOptions(XlsxLineLayoutOptions)方法設置 PDF 到 XLSX 轉換選項。
- 使用PdfDocument.SaveToFile(filePath, FileFormat.XLSX)方法將文檔保存到 Excel?。
[C#]
using Spire.Pdf; using Spire.Pdf.Conversion;namespace ConvertPdfToExcel { class Program { static void Main(string[] args) { //Initialize an instance of PdfDocument class PdfDocument pdf = new PdfDocument(); //Load the PDF document pdf.LoadFromFile("Sample1.pdf");//Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false. //The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText XlsxLineLayoutOptions options = new XlsxLineLayoutOptions(false, true, true, true); //Set PDF to XLSX convert options pdf.ConvertOptions.SetPdfToXlsxOptions(options);//Save the PDF document to XLSX pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX); } } }
[VB.NET]
Imports Spire.Pdf Imports Spire.Pdf.ConversionNamespace ConvertPdfToExcel Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Initialize an instance of PdfDocument class Dim pdf As PdfDocument = New PdfDocument() 'Load the PDF document pdf.LoadFromFile("Sample1.pdf")'Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false. 'The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText Dim options As XlsxLineLayoutOptions = New XlsxLineLayoutOptions(False, True, True, True) 'Set PDF to XLSX convert options pdf.ConvertOptions.SetPdfToXlsxOptions(options)'Save the PDF document to XLSX pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX) End Sub End Class End Namespace
以上便是如何在C#/VB.NET:將 PDF 轉換為 Excel,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程。