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

相关推荐
Java资深爱好者4 小时前
VB.NET中如何利用ASP.NET进行Web开发
前端·asp.net·.net
Lingbug7 小时前
.Net日志组件之NLog的使用和配置
后端·c#·.net·.netcore
徐同保8 小时前
vue 在线预览word和excel
vue.js·word·excel
kaixin_啊啊12 小时前
计算机二级office操作技巧——Excel篇
excel
那个那个鱼16 小时前
.NET 框架版本年表
开发语言·c#·.net
小乖兽技术17 小时前
fo-dicom,第一个基于.NET Standard 2.0 开发的DICOM开源库
.net·fo-dicom
nigture17 小时前
.NET全局静态可访问IServiceProvider(支持Blazor)
.net·ioc·di·rougamo
~在杰难逃~1 天前
关于订单信息的Excel数据分析报告
笔记·数据分析·excel·数据分析报告
海绵波波1071 天前
Zotero使用(一)PDF文件导入不会自动识别
pdf
2401_856926931 天前
图片转PDF技巧揭秘:四款高效工具推荐!
学习·pdf·图片转pdf·图片转pdf工具