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

测试结果:

相关推荐
zbguolei3 小时前
上传 Excel 文件进行数据库比对
数据库·excel
我爱娃哈哈5 小时前
SpringBoot集成:5分钟实现HTML转PDF功能
spring boot·pdf·html
henreash5 小时前
C#调用F#的MailboxProcessor
开发语言·c#
未来之窗软件服务5 小时前
幽冥大陆(八十九 ) 自动化在线打包任意平台软件 —东方仙盟练气期
开发语言·c#·自动化·仙盟创梦ide·东方仙盟·在线打包
kylezhao20196 小时前
第四节、C# 上位机面向对象编程详解(工控硬件继承实战版)
c#·工控上位机
光泽雨6 小时前
ST语言与C#语言数据类型对比详解
开发语言·c#
南风花海7 小时前
使用ERP时出现Excel插件(ESClient10)加载失败,请检查是否被禁用了。
excel
kylezhao20199 小时前
第三节、C# 上位机面向对象编程详解(工控硬件封装实战版)
开发语言·前端·c#
kingwebo'sZone9 小时前
c# 遍历 根据控件名获取控件实例
开发语言·c#
2501_9071368210 小时前
好用的excel聚光灯插件
excel·软件需求