將 PDF 轉換為 Excel
Spire.PDF for .NET 是一款專門對 Word 文檔進行操作的 .NET 類庫。致力于在于幫助開發人員輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔,而無需安裝 Microsoft Word。
行號用于在每行文本旁邊顯示 Word 自動計算的行數。當我們需要參考合同或法律文件等文檔中的特定行時,它非常有用。word中的行號功能允許我們設置起始值、編號間隔、與文本的距離以及行號的編號方式。使用 Spire.Doc,我們可以實現上述所有功能。本文將介紹如何將 HTML 轉換為 PDF。
歡迎加入spire技術交流群:767755948
PDF 是一種多功能文件格式,但很難編輯。如果您想修改和計算 PDF 數據,將 PDF 轉換為 Excel 將是一個理想的解決方案。在本文中,您將學習如何使用 Spire.PDF for .NET 在 C# 和 VB.NET 中將 PDF 轉換為 Excel。
- 將 PDF 轉換為 Excel
- 將多頁 PDF 轉換為一個 Excel 工作表
安裝 Spire.PDF for .NET
首先,您需要將 Spire.PDF for.NET 軟件包中包含的 DLL 文件作為引用添加到您的 .NET 項目中。這些 DLL 文件既可以從這個鏈接下載,也可以通過 NuGet 安裝。
1 PM> Install-Package Spire.PDF
用 C# 和 VB.NET 將 PDF 轉換為 Excel
以下是將 PDF 文檔轉換為 Excel 的步驟:
- 初始化一個 PdfDocument 類的實例。
- 使用PdfDocument.LoadFromFile(filePath)方法加載PDF文檔。
- 使用 PdfDocument.SaveToFile(filePath, FileFormat.XLSX) 方法將文檔保存到 Excel。
01	using Spire.Pdf;
02	using Spire.Pdf.Conversion;
03	 
04	namespace ConvertPdfToExcel
05	{
06	    class Program
07	    {
08	        static void Main(string[] args)
09	        {
10	            //Initialize an instance of PdfDocument class
11	            PdfDocument pdf = new PdfDocument();
12	            //Load the PDF document
13	            pdf.LoadFromFile("Sample.pdf");
14	 
15	            //Save the PDF document to XLSX
16	            pdf.SaveToFile("PdfToExcel.xlsx", FileFormat.XLSX);
17	        }
18	    }
19	}
[VB.NET]
01	Imports Spire.Pdf
02	Imports Spire.Pdf.Conversion
03	 
04	Namespace ConvertPdfToExcel
05	    Friend Class Program
06	        Private Shared Sub Main(ByVal args As String())
07	            'Initialize an instance of PdfDocument class
08	            Dim pdf As PdfDocument = New PdfDocument()
09	            'Load the PDF document
10	            pdf.LoadFromFile("Sample.pdf")
11	 
12	            'Save the PDF document to XLSX
13	            pdf.SaveToFile("PdfToExcel.xlsx", FileFormat.XLSX)
14	        End Sub
15	    End Class
16	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中。
01	using Spire.Pdf;
02	using Spire.Pdf.Conversion;
03	 
04	namespace ConvertPdfToExcel
05	{
06	    class Program
07	    {
08	        static void Main(string[] args)
09	        {
10	            //Initialize an instance of PdfDocument class
11	            PdfDocument pdf = new PdfDocument();
12	            //Load the PDF document
13	            pdf.LoadFromFile("Sample1.pdf");
14	 
15	            //Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
16	            //The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText
17	            XlsxLineLayoutOptions options = new XlsxLineLayoutOptions(false, true, true, true);
18	            //Set PDF to XLSX convert options
19	            pdf.ConvertOptions.SetPdfToXlsxOptions(options);
20	 
21	            //Save the PDF document to XLSX
22	            pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX);
23	        }
24	    }
25	}
[VB.NET]
01	Imports Spire.Pdf
02	Imports Spire.Pdf.Conversion
03	 
04	Namespace ConvertPdfToExcel
05	    Friend Class Program
06	        Private Shared Sub Main(ByVal args As String())
07	            'Initialize an instance of PdfDocument class
08	            Dim pdf As PdfDocument = New PdfDocument()
09	            'Load the PDF document
10	            pdf.LoadFromFile("Sample1.pdf")
11	 
12	            'Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
13	            'The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText
14	            Dim options As XlsxLineLayoutOptions = New XlsxLineLayoutOptions(False, True, True, True)
15	            'Set PDF to XLSX convert options
16	            pdf.ConvertOptions.SetPdfToXlsxOptions(options)
17	 
18	            'Save the PDF document to XLSX
19	            pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX)
20	        End Sub
21	    End Class
22	End Namespace
	 
 
	
		申請臨時許可證
若想從生成的文檔中刪除評估信息,或解除功能限制,申請 30 天試用許可證。
	

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線