基于python的excel检查和读写软件

2023-12-24 07:20

本文主要是介绍基于python的excel检查和读写软件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

软件版本:python3.6

窗口和界面gui代码:

class mygui:def _init_(self):passdef run(self):root = Tkinter.Tk()root.title('ExcelRun')max_w, max_h = root.maxsize()root.geometry(f'500x500+{int((max_w - 500) / 2)}+{int((max_h - 300) / 2)}')  # 居中显示root.resizable(width=False, height=False)# 标签组件label = Tkinter.Label(root, text='from_xlsx:', font=('宋体', 10))label.place(x=40, y=35)# 输入框控件entry_text = Tkinter.StringVar()entry = Tkinter.Entry(root, textvariable=entry_text, font=('FangSong', 10), width=40, state='readonly')entry.place(x=120, y=38)idlabel1 = Tkinter.Label(root, text='ID:', font=('宋体', 10))idlabel1.place(x=70, y=58)fpath1_num1 = Tkinter.StringVar()entry2 = Tkinter.Entry(root, textvariable=fpath1_num1, font=('FangSong', 10), width=10)entry2.place(x=120, y=58)idlabel2 = Tkinter.Label(root, text='score:', font=('宋体', 12))idlabel2.place(x=240, y=53)fpath1_num2 = Tkinter.StringVar()entry3 = Tkinter.Entry(root, textvariable=fpath1_num2, font=('FangSong', 10), width=10)entry3.place(x=300, y=58)label2 = Tkinter.Label(root, text='to_xls:', font=('宋体', 12))label2.place(x=40, y=78)filepath2 = Tkinter.StringVar()filepath2entry = Tkinter.Entry(root, textvariable=filepath2, font=('FangSong', 10), width=40, state='readonly')filepath2entry.place(x=120, y=78)id2label1 = Tkinter.Label(root, text='ID:', font=('宋体', 10))id2label1.place(x=70, y=98)filepath2_num1 = Tkinter.StringVar()filepath2_num1entry = Tkinter.Entry(root, textvariable=filepath2_num1, font=('FangSong', 10), width=10)filepath2_num1entry.place(x=120, y=98)id2label2 = Tkinter.Label(root, text='loc:', font=('宋体', 12))id2label2.place(x=240, y=93)filepath2_num2 = Tkinter.StringVar()filepath2_num2entry = Tkinter.Entry(root, textvariable=filepath2_num2, font=('FangSong', 10), width=10)filepath2_num2entry.place(x=300, y=98)button = Tkinter.Button(root, text='选择路径', command=lambda: self.get_path(entry_text,outputtext))button.place(x=410, y=30)button_path2 = Tkinter.Button(root, text='选择路径', command=lambda: self.get_path(filepath2,outputtext))button_path2.place(x=410, y=78)button2 = Tkinter.Button(root, text='重名检查', command=lambda: self.get_path2(entry_text,outputtext,fpath1_num1))button2.place(x=410, y=128)button3 = Tkinter.Button(root, text='成绩转移', command=lambda: self.get_path3(\entry_text.get(),int(fpath1_num1.get()),int(fpath1_num2.get()),\filepath2.get(),int(filepath2_num1.get()),int(filepath2_num2.get()),outputtext))button3.place(x=410, y=158)button4 = Tkinter.Button(root, text='名单核查', command=lambda: self.get_path4(\entry_text.get(),int(fpath1_num1.get()),\filepath2.get(),int(filepath2_num1.get()),outputtext))button4.place(x=410, y=188)outputtext = Text(root, height=20, width=40)# 将多行输入文本放入(pack)窗口中outputtext.place(x=120, y=120)var='a' lst=[chr(ord(var)+i) for i in range(26)]for i in range(0,26):outputtext.insert("end",lst[i]+'  '+str(i)+'\t')if (i+2)%3==1:outputtext.insert("end",'\n')root.mainloop()f=mygui()

excel检查和读写代码:

from xlrd import open_workbook
from xlutils.copy import copy
import xlrd
import os
import randomclass zuoye__2_excel:def run(self,path1,p1num1,p1num2,path2xls,p2num1,p2num2):dic={}dic2={}rb2 = open_workbook(path1)rs2 = rb2.sheet_by_index(0)nrows = rs2.nrowsncols = rs2.ncolswb = copy(rb2)#通过get_sheet()获取的sheet有write()方法ws = wb.get_sheet(0)#ws.write(0, 0, 'changed!')# for i in range(0, nrows):#########################################################################################################id=rs2.cell_value(i,p1num1)id=int(id)sc=rs2.cell_value(i,p1num2)dic[id]=sc#INDEX=rs.cell_value(i,2)##########################################################################################################name=rs.cell_value(i,1)#########################################################################################################rb2 = open_workbook(path2xls)rs2 = rb2.sheet_by_index(0)nrows2 = rs2.nrowsncols2 = rs2.ncolswb2 = copy(rb2)#通过get_sheet()获取的sheet有write()方法ws2 = wb2.get_sheet(0)#ws.write(0, 0, 'changed!')for i in range(0, nrows2):id1=rs2.cell_value(i,p2num1)#id3= id1.replace(" ", "")if type(id1)==str or not id1>0 :continueid2=int(id1)#id2=''.join([i for i in id3 if  i.isdigit()])#name2=rs2.cell_value(i,6)#dic2[id2]=i#dic[id2]=rs2.cell_value(i,5)if  id2  in dic:#########################################################################################################ws2.write(i,p2num2, dic[id2])else:print(id2)filepath='w'+str(random.randint(10000, 30000))+'.xls'if  os.path.exists(filepath):print('文件存在!')return '文件存在,重新保存!'else:wb2.save(filepath)return '文件保存到:'+filepath+'!';

这篇关于基于python的excel检查和读写软件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/530997

相关文章

Python函数作用域示例详解

《Python函数作用域示例详解》本文介绍了Python中的LEGB作用域规则,详细解析了变量查找的四个层级,通过具体代码示例,展示了各层级的变量访问规则和特性,对python函数作用域相关知识感兴趣... 目录一、LEGB 规则二、作用域实例2.1 局部作用域(Local)2.2 闭包作用域(Enclos

Python实现对阿里云OSS对象存储的操作详解

《Python实现对阿里云OSS对象存储的操作详解》这篇文章主要为大家详细介绍了Python实现对阿里云OSS对象存储的操作相关知识,包括连接,上传,下载,列举等功能,感兴趣的小伙伴可以了解下... 目录一、直接使用代码二、详细使用1. 环境准备2. 初始化配置3. bucket配置创建4. 文件上传到os

使用Python实现可恢复式多线程下载器

《使用Python实现可恢复式多线程下载器》在数字时代,大文件下载已成为日常操作,本文将手把手教你用Python打造专业级下载器,实现断点续传,多线程加速,速度限制等功能,感兴趣的小伙伴可以了解下... 目录一、智能续传:从崩溃边缘抢救进度二、多线程加速:榨干网络带宽三、速度控制:做网络的好邻居四、终端交互

Python中注释使用方法举例详解

《Python中注释使用方法举例详解》在Python编程语言中注释是必不可少的一部分,它有助于提高代码的可读性和维护性,:本文主要介绍Python中注释使用方法的相关资料,需要的朋友可以参考下... 目录一、前言二、什么是注释?示例:三、单行注释语法:以 China编程# 开头,后面的内容为注释内容示例:示例:四

Python中win32包的安装及常见用途介绍

《Python中win32包的安装及常见用途介绍》在Windows环境下,PythonWin32模块通常随Python安装包一起安装,:本文主要介绍Python中win32包的安装及常见用途的相关... 目录前言主要组件安装方法常见用途1. 操作Windows注册表2. 操作Windows服务3. 窗口操作

Python中re模块结合正则表达式的实际应用案例

《Python中re模块结合正则表达式的实际应用案例》Python中的re模块是用于处理正则表达式的强大工具,正则表达式是一种用来匹配字符串的模式,它可以在文本中搜索和匹配特定的字符串模式,这篇文章主... 目录前言re模块常用函数一、查看文本中是否包含 A 或 B 字符串二、替换多个关键词为统一格式三、提

Java easyExcel实现导入多sheet的Excel

《JavaeasyExcel实现导入多sheet的Excel》这篇文章主要为大家详细介绍了如何使用JavaeasyExcel实现导入多sheet的Excel,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录1.官网2.Excel样式3.代码1.官网easyExcel官网2.Excel样式3.代码

python常用的正则表达式及作用

《python常用的正则表达式及作用》正则表达式是处理字符串的强大工具,Python通过re模块提供正则表达式支持,本文给大家介绍python常用的正则表达式及作用详解,感兴趣的朋友跟随小编一起看看吧... 目录python常用正则表达式及作用基本匹配模式常用正则表达式示例常用量词边界匹配分组和捕获常用re

python实现对数据公钥加密与私钥解密

《python实现对数据公钥加密与私钥解密》这篇文章主要为大家详细介绍了如何使用python实现对数据公钥加密与私钥解密,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录公钥私钥的生成使用公钥加密使用私钥解密公钥私钥的生成这一部分,使用python生成公钥与私钥,然后保存在两个文

python删除xml中的w:ascii属性的步骤

《python删除xml中的w:ascii属性的步骤》使用xml.etree.ElementTree删除WordXML中w:ascii属性,需注册命名空间并定位rFonts元素,通过del操作删除属... 可以使用python的XML.etree.ElementTree模块通过以下步骤删除XML中的w:as