基于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开发中,获取Python版本号是调试、兼容性检查和版本控制的重要基础操作,本文详细介绍了如何使用sys和platform模块获取Python的主... 目录1. python版本号获取基础2. 使用sys模块获取版本信息2.1 sys模块概述2.1.1

一文详解Python如何开发游戏

《一文详解Python如何开发游戏》Python是一种非常流行的编程语言,也可以用来开发游戏模组,:本文主要介绍Python如何开发游戏的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录一、python简介二、Python 开发 2D 游戏的优劣势优势缺点三、Python 开发 3D

Python函数作用域与闭包举例深度解析

《Python函数作用域与闭包举例深度解析》Python函数的作用域规则和闭包是编程中的关键概念,它们决定了变量的访问和生命周期,:本文主要介绍Python函数作用域与闭包的相关资料,文中通过代码... 目录1. 基础作用域访问示例1:访问全局变量示例2:访问外层函数变量2. 闭包基础示例3:简单闭包示例4

Python实现字典转字符串的五种方法

《Python实现字典转字符串的五种方法》本文介绍了在Python中如何将字典数据结构转换为字符串格式的多种方法,首先可以通过内置的str()函数进行简单转换;其次利用ison.dumps()函数能够... 目录1、使用json模块的dumps方法:2、使用str方法:3、使用循环和字符串拼接:4、使用字符

Python版本与package版本兼容性检查方法总结

《Python版本与package版本兼容性检查方法总结》:本文主要介绍Python版本与package版本兼容性检查方法的相关资料,文中提供四种检查方法,分别是pip查询、conda管理、PyP... 目录引言为什么会出现兼容性问题方法一:用 pip 官方命令查询可用版本方法二:conda 管理包环境方法

基于Python开发Windows自动更新控制工具

《基于Python开发Windows自动更新控制工具》在当今数字化时代,操作系统更新已成为计算机维护的重要组成部分,本文介绍一款基于Python和PyQt5的Windows自动更新控制工具,有需要的可... 目录设计原理与技术实现系统架构概述数学建模工具界面完整代码实现技术深度分析多层级控制理论服务层控制注

pycharm跑python项目易出错的问题总结

《pycharm跑python项目易出错的问题总结》:本文主要介绍pycharm跑python项目易出错问题的相关资料,当你在PyCharm中运行Python程序时遇到报错,可以按照以下步骤进行排... 1. 一定不要在pycharm终端里面创建环境安装别人的项目子模块等,有可能出现的问题就是你不报错都安装

Python打包成exe常用的四种方法小结

《Python打包成exe常用的四种方法小结》本文主要介绍了Python打包成exe常用的四种方法,包括PyInstaller、cx_Freeze、Py2exe、Nuitka,文中通过示例代码介绍的非... 目录一.PyInstaller11.安装:2. PyInstaller常用参数下面是pyinstal

Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题

《Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题》在爬虫工程里,“HTTPS”是绕不开的话题,HTTPS为传输加密提供保护,同时也给爬虫带来证书校验、... 目录一、核心问题与优先级检查(先问三件事)二、基础示例:requests 与证书处理三、高并发选型:

Python中isinstance()函数原理解释及详细用法示例

《Python中isinstance()函数原理解释及详细用法示例》isinstance()是Python内置的一个非常有用的函数,用于检查一个对象是否属于指定的类型或类型元组中的某一个类型,它是Py... 目录python中isinstance()函数原理解释及详细用法指南一、isinstance()函数