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

测试结果:

相关推荐
SunflowerCoder2 小时前
EF Core + PostgreSQL 配置表设计踩坑记录:从 23505 到 ChangeTracker 冲突
数据库·postgresql·c#·efcore
阿蒙Amon5 小时前
C#每日面试题-常量和只读变量的区别
java·面试·c#
我是唐青枫5 小时前
C#.NET ConcurrentBag<T> 设计原理与使用场景
c#·.net
大王小生5 小时前
C# CancellationToken
开发语言·c#·token·cancellation
listhi5205 小时前
基于C#实现屏幕放大镜功能
开发语言·c#
该用户已不存在8 小时前
不止是初始化,4个C# 构造函数解析与实例
后端·c#·.net
无风听海11 小时前
深入讲解 C# 中 string 如何支持 CultureInfo
开发语言·c#
wzfj1234512 小时前
FreeRTOS xTaskCreateStatic 详解
开发语言·c#
kylezhao201912 小时前
C# DataGridView 控件使用详解
c#
一个帅气昵称啊12 小时前
C# 14 中的新增功能
开发语言·c#