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

相关推荐
不想有bug的小菜鸟14 分钟前
vue3使用iframe全屏展示pdf效果
前端·pdf
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
学海无涯,行者无疆11 小时前
使用Jenkins实现Windows服务器下C#应用程序发布
windows·c#·jenkins·.net·cicd·自动发布·一键发布
Smilecoc13 小时前
excel单、双字节字符转换函数(中英文输入法符号转换)
excel
Terry_trans13 小时前
工作中遇到的EXCEL小问题:多行有间隔符的合并
excel
舊時王謝堂前燕13 小时前
Vue2+Element实现Excel文件上传下载预览【超详细图解】
excel
如意机反光镜裸15 小时前
一键导出数据库表到Excel
数据库·excel·导出
喵叔哟15 小时前
7. 【.NET 8 实战--孢子记账--从单体到微服务--转向微服务】--微服务基础工具与技术--Ocelot 网关--路由
微服务·架构·.net
玩c#的小杜同学16 小时前
从“Switch-case“到“智能模式“:C#模式匹配的终极进化指南
开发语言·前端·c#·.net
XMYX-017 小时前
用Python3脚本实现Excel数据到TXT文件的智能转换:自动化办公新姿势
python·自动化·excel