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

2023-12-25 18:45

本文主要是介绍基于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/536552

相关文章

Python+Tkinter实现Windows Hosts文件编辑管理工具

《Python+Tkinter实现WindowsHosts文件编辑管理工具》在日常开发和网络调试或科学上网场景中,Hosts文件修改是每个开发者都绕不开的必修课,本文将完整解析一个基于Python... 目录一、前言:为什么我们需要专业的Hosts管理工具二、工具核心功能全景图2.1 基础功能模块2.2 进

Python多重继承慎用的地方

《Python多重继承慎用的地方》多重继承也可能导致一些问题,本文主要介绍了Python多重继承慎用的地方,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录前言多重继承要慎用Mixin模式最后前言在python中,多重继承是一种强大的功能,它允许一个

python+OpenCV反投影图像的实现示例详解

《python+OpenCV反投影图像的实现示例详解》:本文主要介绍python+OpenCV反投影图像的实现示例详解,本文通过实例代码图文并茂的形式给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一、前言二、什么是反投影图像三、反投影图像的概念四、反向投影的工作原理一、利用反向投影backproj

Python中edge-tts实现便捷语音合成

《Python中edge-tts实现便捷语音合成》edge-tts是一个功能强大的Python库,支持多种语言和声音选项,本文主要介绍了Python中edge-tts实现便捷语音合成,具有一定的参考价... 目录安装与环境设置文本转语音查找音色更改语音参数生成音频与字幕总结edge-tts 是一个功能强大的

使用Python和PaddleOCR实现图文识别的代码和步骤

《使用Python和PaddleOCR实现图文识别的代码和步骤》在当今数字化时代,图文识别技术的应用越来越广泛,如文档数字化、信息提取等,PaddleOCR是百度开源的一款强大的OCR工具包,它集成了... 目录一、引言二、环境准备2.1 安装 python2.2 安装 PaddlePaddle2.3 安装

Python+PyQt5开发一个Windows电脑启动项管理神器

《Python+PyQt5开发一个Windows电脑启动项管理神器》:本文主要介绍如何使用PyQt5开发一款颜值与功能并存的Windows启动项管理工具,不仅能查看/删除现有启动项,还能智能添加新... 目录开篇:为什么我们需要启动项管理工具功能全景图核心技术解析1. Windows注册表操作2. 启动文件

Python datetime 模块概述及应用场景

《Pythondatetime模块概述及应用场景》Python的datetime模块是标准库中用于处理日期和时间的核心模块,本文给大家介绍Pythondatetime模块概述及应用场景,感兴趣的朋... 目录一、python datetime 模块概述二、datetime 模块核心类解析三、日期时间格式化与

Java调用Python的四种方法小结

《Java调用Python的四种方法小结》在现代开发中,结合不同编程语言的优势往往能达到事半功倍的效果,本文将详细介绍四种在Java中调用Python的方法,并推荐一种最常用且实用的方法,希望对大家有... 目录一、在Java类中直接执行python语句二、在Java中直接调用Python脚本三、使用Run

使用Python开发Markdown兼容公式格式转换工具

《使用Python开发Markdown兼容公式格式转换工具》在技术写作中我们经常遇到公式格式问题,例如MathML无法显示,LaTeX格式错乱等,所以本文我们将使用Python开发Markdown兼容... 目录一、工具背景二、环境配置(Windows 10/11)1. 创建conda环境2. 获取XSLT

Python如何调用指定路径的模块

《Python如何调用指定路径的模块》要在Python中调用指定路径的模块,可以使用sys.path.append,importlib.util.spec_from_file_location和exe... 目录一、sys.path.append() 方法1. 方法简介2. 使用示例3. 注意事项二、imp