C#PDF转Excel

組件 Spire.Pdf.dll, v7.8.9.0 【注意:版本太低的没有此功能】

在Visual Studio中找到参考,鼠标右键点击"引用","添加引用",将本地路径debug文件夹下的dll文件添加引用至程序。

界面图:

1个label,1个TextBox文本框(属性Multiline改为ture可以拖动改变文本框大小),2个Botton按钮

【PDF转Excel】

转换时,可通过以下步骤来实现,仅需要三行代码:

  • 创建 PdfDocument类的对象。
  • 调用 PdfDocument.LoadFromFile(string filename) 方法加载PDF文档。
  • 通过 PdfDocument.SaveToFile(string filename, FileFormat fileFormat) 方法将文件保存为Excel格式到指定路径。
cs 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Spire.Pdf;
using excelToPdf;


namespace PdfToExcel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DialogOperate openfile = new DialogOperate();
        public void pdfCovertExcel(string path)
        {
            //加载PDF文档
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(path);//pdf文件路径
            //保存为Excel文档
            pdf.SaveToFile("demo.xlsx", FileFormat.XLSX);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pdfCovertExcel(textBox1.Text);
            MessageBox.Show("转换完成");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text=openfile.OpenFile();
        }
    }
}

测试结果:

相关推荐
曹牧13 小时前
C#:输入的字符串格式不正确
c#
Allstar_4317 小时前
制造业研发管理数字化:从 Excel 到专业 APQP 系统的架构选型思考
架构·excel
驾驭人生17 小时前
NET NPOI 实战:生成带下拉、数据校验、必填标红的 Excel 导入模板
excel
shmily麻瓜小菜鸡17 小时前
前端实现图片与PDF文字识别敏感信息打码方案
前端·pdf·状态模式
泡海椒17 小时前
把 TRANSFORM 做成可扩展能力:JQuick-Excel 的函数与 SPI 调用链
驱动开发·excel
根号五18 小时前
JetBrains Rider 使用教程(1)新建解决方案
c#·jetbrains rider
2601_9627809119 小时前
2027采购岗准备:大数据管理与应用专业如何把Excel、SQL变成业务能力
excel
海天鹰19 小时前
C#:接收从打开方式打开的参数
c#
宝桥南山19 小时前
.NET 11 - 尝试一下Minimal API中的异步验证新特性
microsoft·微软·c#·asp.net·.net·.netcore
开开心心_Every20 小时前
文件查重软件批量删除重复文件释放空间
java·开发语言·c#·计算机外设·ocr·excel·perl