|
本帖最后由 MRmuzi 于 2021-6-20 15:32 编辑
老哥,可以加个QQ:1010067363 这个弄出来的话我给您点报酬,也不能让您白帮我,谢谢您。源excle文件过大,这里上传不了,加QQ我发您
from tkinter import Button, Entry, StringVar, Tk
from openpyxl import load_workbook
from openpyxl.styles import PatternFill
def rtnkey(event=None):
# 获取输入框中的内容 67480
str_data = e.get()
arr_data = str_data.split(',')
print(arr_data)
# arr_data = [int(x) for x in arr_data]
# print(arr_data)
wb = load_workbook("E:\\5P1.xlsx")
# 默认选择第一张sheet表
ws = wb.active
sheet = wb.get_sheet_by_name('Sheet1')
sheet.max_row
sheet.max_column
# 选取数据区
cells = ws.iter_rows(min_row=1, min_col=sheet.max_column, max_col=sheet.max_column)
# 构建颜色对象,start_color表示前景色,end_color表示背景色。
green_fill = PatternFill("solid", start_color='00E400')
yellow_fill = PatternFill("solid", start_color='FFFF00')
orange_fill = PatternFill('solid', start_color='FF7E00')
red_fill = PatternFill('solid', start_color='FF0000')
pink_fill = PatternFill('solid', start_color='99004C')
maroon_fill = PatternFill('solid', start_color='7E0023')
for i in cells:
# 每行的内容是元组,每个元组只有一个单元格,所以取第一项的value,然后转为int型
for arr_datas in arr_data:
value = int(arr_datas)
wb.save("new_sheet.xlsx")
wb.close()
if __name__ == '__main__':
# 新建输入窗口
root = Tk()
e = StringVar()
entry = Entry(root, show='', font=('Arial', 14), validate='key', textvariable=e, width=50)
entry.pack()
entry = Button(root, text="执行命令")
entry.bind('<Button-1>', rtnkey)
root.title('查询窗口')
root.geometry("500x300")
entry.place(relx=0.5, rely=0.5, anchor="center")
root.mainloop() |
|