基于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将博客内容html导出为Markdown格式

《Python将博客内容html导出为Markdown格式》Python将博客内容html导出为Markdown格式,通过博客url地址抓取文章,分析并提取出文章标题和内容,将内容构建成html,再转... 目录一、为什么要搞?二、准备如何搞?三、说搞咱就搞!抓取文章提取内容构建html转存markdown

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

Python Websockets库的使用指南

《PythonWebsockets库的使用指南》pythonwebsockets库是一个用于创建WebSocket服务器和客户端的Python库,它提供了一种简单的方式来实现实时通信,支持异步和同步... 目录一、WebSocket 简介二、python 的 websockets 库安装三、完整代码示例1.

揭秘Python Socket网络编程的7种硬核用法

《揭秘PythonSocket网络编程的7种硬核用法》Socket不仅能做聊天室,还能干一大堆硬核操作,这篇文章就带大家看看Python网络编程的7种超实用玩法,感兴趣的小伙伴可以跟随小编一起... 目录1.端口扫描器:探测开放端口2.简易 HTTP 服务器:10 秒搭个网页3.局域网游戏:多人联机对战4.

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

Python使用自带的base64库进行base64编码和解码

《Python使用自带的base64库进行base64编码和解码》在Python中,处理数据的编码和解码是数据传输和存储中非常普遍的需求,其中,Base64是一种常用的编码方案,本文我将详细介绍如何使... 目录引言使用python的base64库进行编码和解码编码函数解码函数Base64编码的应用场景注意

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

Python如何使用__slots__实现节省内存和性能优化

《Python如何使用__slots__实现节省内存和性能优化》你有想过,一个小小的__slots__能让你的Python类内存消耗直接减半吗,没错,今天咱们要聊的就是这个让人眼前一亮的技巧,感兴趣的... 目录背景:内存吃得满满的类__slots__:你的内存管理小助手举个大概的例子:看看效果如何?1.