PDF控件Spire.PDF for .NET【转换】演示:将 PDF 转换为 Excel

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.Conversion

Namespace 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: Convert PDF to Excel

使用 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.Conversion

Namespace 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

以上便是如何在C#/VB.NET:将 PDF 转换为 Excel,如果您有其他问题也可以继续浏览本系列文章,获取相关教程。

猜你喜欢

转载自blog.csdn.net/m0_67129275/article/details/134925989
今日推荐