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();
        }
    }
}

测试结果:

相关推荐
Song_da_da_2 小时前
C#与VisionPro联合编程实战:机器视觉二次开发完整指南
开发语言·microsoft·c#
百事牛科技3 小时前
两种方法锁定 PDF,拒绝内容被随意篡改
windows·pdf
加号34 小时前
【C#】 Web API 自定义配置函数请求路径:从路由本质到灵活架构设计
开发语言·c#
HappyAcmen6 小时前
1.pdfplumber安装,PDF文字提取
python·pdf
Codiggerworld6 小时前
Vim 实战:在 VS Code、JetBrains、终端里玩转 Vim
编辑器·vim·excel
happyprince7 小时前
11-Hugging Face Transformers 分布式与并行系统深度分析
分布式·c#·wpf
开开心心_Every8 小时前
多连接方式的屏幕共享工具推荐
运维·服务器·pdf·电脑·excel·tornado·dash
csdn_aspnet9 小时前
C# list集合 多属性排序
c#·list·linq·排序
加号39 小时前
【WPF】 基于 Canvas 读取并渲染 DXF 文件的技术指南
c#·wpf
天下无敌笨笨熊9 小时前
SNMP协议开发心得
网络协议·c#