基于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: 多模块(.py)中全局变量的导入

文章目录 global关键字可变类型和不可变类型数据的内存地址单模块(单个py文件)的全局变量示例总结 多模块(多个py文件)的全局变量from x import x导入全局变量示例 import x导入全局变量示例 总结 global关键字 global 的作用范围是模块(.py)级别: 当你在一个模块(文件)中使用 global 声明变量时,这个变量只在该模块的全局命名空

10. 文件的读写

10.1 文本文件 操作文件三大类: ofstream:写操作ifstream:读操作fstream:读写操作 打开方式解释ios::in为了读文件而打开文件ios::out为了写文件而打开文件,如果当前文件存在则清空当前文件在写入ios::app追加方式写文件ios::trunc如果文件存在先删除,在创建ios::ate打开文件之后令读写位置移至文件尾端ios::binary二进制方式

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss

【学习笔记】 陈强-机器学习-Python-Ch15 人工神经网络(1)sklearn

系列文章目录 监督学习:参数方法 【学习笔记】 陈强-机器学习-Python-Ch4 线性回归 【学习笔记】 陈强-机器学习-Python-Ch5 逻辑回归 【课后题练习】 陈强-机器学习-Python-Ch5 逻辑回归(SAheart.csv) 【学习笔记】 陈强-机器学习-Python-Ch6 多项逻辑回归 【学习笔记 及 课后题练习】 陈强-机器学习-Python-Ch7 判别分析 【学

软件设计师备考——计算机系统

学习内容源自「软件设计师」 上午题 #1 计算机系统_哔哩哔哩_bilibili 目录 1.1.1 计算机系统硬件基本组成 1.1.2 中央处理单元 1.CPU 的功能 1)运算器 2)控制器 RISC && CISC 流水线控制 存储器  Cache 中断 输入输出IO控制方式 程序查询方式 中断驱动方式 直接存储器方式(DMA)  ​编辑 总线 ​编辑

nudepy,一个有趣的 Python 库!

更多资料获取 📚 个人网站:ipengtao.com 大家好,今天为大家分享一个有趣的 Python 库 - nudepy。 Github地址:https://github.com/hhatto/nude.py 在图像处理和计算机视觉应用中,检测图像中的不适当内容(例如裸露图像)是一个重要的任务。nudepy 是一个基于 Python 的库,专门用于检测图像中的不适当内容。该

【STM32】SPI通信-软件与硬件读写SPI

SPI通信-软件与硬件读写SPI 软件SPI一、SPI通信协议1、SPI通信2、硬件电路3、移位示意图4、SPI时序基本单元(1)开始通信和结束通信(2)模式0---用的最多(3)模式1(4)模式2(5)模式3 5、SPI时序(1)写使能(2)指定地址写(3)指定地址读 二、W25Q64模块介绍1、W25Q64简介2、硬件电路3、W25Q64框图4、Flash操作注意事项软件SPI读写W2

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

HTML提交表单给python

python 代码 from flask import Flask, request, render_template, redirect, url_forapp = Flask(__name__)@app.route('/')def form():# 渲染表单页面return render_template('./index.html')@app.route('/submit_form',