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,如果您有其他问题也可以继续浏览本系列文章,获取相关教程。

最近更新

  1. TCP协议是安全的吗?

    2023-12-12 07:30:07       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-12 07:30:07       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-12 07:30:07       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-12 07:30:07       20 阅读

热门阅读

  1. Spring-xml版本

    2023-12-12 07:30:07       44 阅读
  2. Mysql mybatis 语法示例

    2023-12-12 07:30:07       41 阅读
  3. Docker与K8s的区别

    2023-12-12 07:30:07       38 阅读
  4. x的平方根算法(leetcode第69题)

    2023-12-12 07:30:07       38 阅读
  5. Flask存储在内存中的密钥被读取

    2023-12-12 07:30:07       38 阅读
  6. MATLAB 2021b 安装教程

    2023-12-12 07:30:07       49 阅读
  7. 微服务学习二

    2023-12-12 07:30:07       44 阅读
  8. 洛谷 P8628 [蓝桥杯 2015 国 AC] 穿越雷区

    2023-12-12 07:30:07       48 阅读
  9. 【Fiddler】IDEA配置Fiddler

    2023-12-12 07:30:07       37 阅读
  10. 面试经典150题(14)

    2023-12-12 07:30:07       39 阅读