世俱杯 2025

logo E-iceblue中文文档

将 PDF 转换为 Excel


Spire.PDF for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。致力于在于帮助开发人员轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档,而无需安装 Microsoft Word。

行号用于在每行文本旁边显示 Word 自动计算的行数。当我们需要参考合同或法律文件等文档中的特定行时,它非常有用。word中的行号功能允许我们设置起始值、编号间隔、与文本的距离以及行号的编号方式。使用 Spire.Doc,我们可以实现上述所有功能。本文将介绍如何将 HTML 转换为 PDF。

Spire.PDF for.NET 最新下载

欢迎加入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。
[C#]
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中。
[C#]
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 天试用许可证。

扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP