吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 14500|回复: 65
收起左侧

[原创工具] 根据pdf转excel的轮子,优化的小工具添加了几个选项。

[复制链接]
wolfwang2008 发表于 2020-3-24 20:27
直接上代码,我直接pyinstaller 打包了,做了个UI。

exe文件直接下载:
链接:https://pan.baidu.com/s/124bJlpb2Z2uwwZWG_sUVmQ
提取码:0b47
复制这段内容后打开百度网盘手机App,操作更方便哦

请大佬多多指教!!!



#-*-coding:utf-8-*-
import tkinter as tk
import tkinter.messagebox
import pdfplumber
import xlwt
from tkinter import filedialog
import os
def file_browse():
    file_path=filedialog.askopenfilename(parent=main_win,initialdir='./',initialfile='tmp',filetypes=[("PDF","*.pdf"),("All files","*")])
    #获取文件路径
    #a=os.path.split(file_path)
    my_file_name.set(file_path)
def page_tran():
    workbook = xlwt.Workbook()  #定义workbook
    sheet = workbook.add_sheet('Sheet1')  #添加sheet
    i = 0 # Excel起始位置
    path = my_file_name.get()
    print(path)    # 导入PDF路径
   
    with pdfplumber.open(path) as pdf:
        w_label4.insert('end','开始读取数据...')
        p=my_page.get()-1 #页数从0开始
     # 获取当前页面的全部文本信息,包括表格中的文字
        page=pdf.pages[p]
     # 获取当前页面的全部文本信息,包括表格中的文字
        for table in page.extract_tables():
                 for row in table:
                     for j in range(len(row)):
                         sheet.write(i, j, row[j])
                     i += 1
                 print('---------- 分割线 ----------')
    path = my_file_name.get()
    a=os.path.split(path)
    b=a[1].split('.')   
    ex_name=a[0]+'/'+b[0]+'-p'+str(p+1)+'.xls'
    workbook.save(ex_name)
    w_label4.insert('end','excel转换成功\n')
   
def index_tran():
    workbook = xlwt.Workbook()  #定义workbook
    sheet = workbook.add_sheet('Sheet1')  #添加sheet
    i = 0 # Excel起始位置
    path = my_file_name.get()
    #print(path)    # 导入PDF路径
   
    with pdfplumber.open(path) as pdf:
        w_label4.insert('end', '开始读取数据...')
        first=my_index1.get()-1
        last=my_index2.get()
        ind_list=list(range(first,last))
        for k in ind_list:
     # 获取当前页面的全部文本信息,包括表格中的文字
            page=pdf.pages[k]
             # 获取当前页面的全部文本信息,包括表格中的文字
            for table in page.extract_tables():
                 for row in table:
                     for j in range(len(row)):
                         sheet.write(i, j, row[j])
                     i += 1
                 print('---------- 分割线 ----------')
    path = my_file_name.get()
    a=os.path.split(path)
    b=a[1].split('.')   
    ex_name=a[0]+'/'+b[0]+'-p'+str(first+1)+'-'+str(last)+'.xls'
    workbook.save(ex_name)
    w_label4.insert('end','excel转换成功\n')
               
def all_tran():
    workbook = xlwt.Workbook()  #定义workbook
    sheet = workbook.add_sheet('Sheet1')  #添加sheet
    i = 0 # Excel起始位置
    path = my_file_name.get()
    print(path)    # 导入PDF路径
   
    with pdfplumber.open(path) as pdf:
        w_label4.insert('end', '开始读取数据...')
        for page in pdf.pages:
             # 获取当前页面的全部文本信息,包括表格中的文字
            for table in page.extract_tables():
                 for row in table:
                     for j in range(len(row)):
                         sheet.write(i, j, row[j])
                     i += 1
                 print('---------- 分割线 ----------')
    path = my_file_name.get()
    a=os.path.split(path)
    b=a[1].split('.')   
    ex_name=a[0]+'/'+b[0]+'.xls'
    workbook.save(ex_name)
    w_label4.insert('end','excel转换成功\n')
def tran2ex():
    print(chkVar1.get())
    if chkVar1.get()==1:
        print(chkVar1.get())
        page_tran()   
    if chkVar1.get()==2:
        print(chkVar2.get())
        index_tran()   
    if chkVar1.get()==3:
        print(chkVar3.get())
        all_tran()
main_win=tk.Tk()
main_win.title('PDF to EXCEL                    Created by Wolf')
main_win.geometry('450x240')
main_win.resizable(width=True, height=True)
w_label1=tk.Label(main_win,text='请选择PDF文件:')
w_label3=tk.Label(main_win,text='到')
w_label4=tk.Text(main_win,width=40,height=1)
#标签
my_file_name=tk.StringVar()
my_entry=tk.Entry(main_win,width=30,textvariable=my_file_name)
#输入kuang
my_page=tk.IntVar()
my_entry_numb3=tk.Entry(main_win,width=5,textvariable=my_page)
my_index1=tk.IntVar()
my_entry_numb1=tk.Entry(main_win,width=5,textvariable=my_index1)
my_index2=tk.IntVar()
my_entry_numb2=tk.Entry(main_win,width=5,textvariable=my_index2)
chkVar1=tk.IntVar()
my_chk3=tk.Radiobutton(main_win,text='全部',variable=chkVar1,value=3)
my_chk1=tk.Radiobutton(main_win,text='单页 ',variable=chkVar1,value=1)
my_chk2=tk.Radiobutton(main_win,text='页数从',variable=chkVar1,value=2)
#单选按钮
my_button3=tk.Button(main_win,text='浏览',command=file_browse)
#浏览文件按钮
my_button1=tk.Button(main_win,width=10,text='转换',command=tran2ex)
my_button2=tk.Button(main_win,width=10,text='退出',command=main_win.quit)
w_label1.place(x=50,y=40)
my_entry.place(x=140,y=40)
my_button3.place(x=360,y=40)
my_chk2.place(x=50,y=100)
my_entry_numb1.place(x=120,y=100)
w_label3.place(x=160,y=100)
my_entry_numb2.place(x=180,y=100)
my_chk1.place(x=50,y=75)
my_entry_numb3.place(x=120,y=75)
my_chk3.place(x=50,y=130)
w_label4.place(x=60,y=160)
my_button1.place(x=120,y=200)
my_button2.place(x=280,y=200)
main_win.mainloop()
123.png

免费评分

参与人数 7吾爱币 +12 热心值 +7 收起 理由
wys5201986 + 1 我很赞同!
linop08 + 1 + 1 谢谢@Thanks!
bb88111 + 1 + 1 点击运行后没有反应,请问会是什么原因,win10 x64
maozheng110 + 1 + 1 鼓励转贴优秀软件安全工具和文档!
jun266662 + 1 + 1 谢谢@Thanks!
微风无敌 + 1 + 1 热心回复!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

linop08 发表于 2020-4-27 09:35
点了完全没反应,win7 64
 楼主| wolfwang2008 发表于 2020-4-28 12:59
linop08 发表于 2020-4-27 09:35
点了完全没反应,win7 64

有没有什么报错信息?今天试了试可以打开,或者你用源码测试下:)
Greenie3 发表于 2020-3-24 20:44
andyle 发表于 2020-3-24 20:48
感谢分享,备用下
看,六眼飞鱼 发表于 2020-3-24 20:58
感谢大佬的优化
polo_123 发表于 2020-3-24 21:02
这真是个好东西,感谢兄弟的分享!
liguibin 发表于 2020-3-24 21:51
挺好的 好东西
Blueyes 发表于 2020-3-24 22:49
  感觉不错~试一试
ihs 发表于 2020-3-25 10:46
实用的工具,感谢分享~
shaynelee 发表于 2020-3-25 15:40
哇,谢谢分享·······
Total_Lau 发表于 2020-3-25 15:47
好的支持下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-26 12:03

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表