想問一下程式讀不到excel問題在那邊呢
import tkinter as tk
from tkinter import filedialog
import openpyxl as xl
def openbook():
fpath = filedialog.askopenfilename()
print(fpath)
if fpath:
pass
wino = tk.Tk()
wino.geometry('200x100')
btno = tk.Button(wino, text='開啟', command=openbook)
btno.pack(side=tk.TOP, expand=tk.YES)
wino.mainloop()
def win_openxls(fpath):
global wino
wino.destroy()
savepath = fpath
w = xl.load_workbook(fpath)
name = w.sheetnames
print(name)
sheet = w[name[0]]
n = sheet.max_row
col = sheet.max_column
def viewclick(event):
global nwin
global tree
global enty
global sitem
global colint
for item in tree.selection():
ttext = tree.item(item, 'values')
sitem = item
col = tree.identify_column(event.x)
colint = int(str(col.replace('#', '')))
nwin = tk.Tk() # 編輯視窗
nwin.geometry("260x100")
label1 = tk.Label(nwin, text="修改:")
label1.pack(side=tk.LEFT, fill=None)
enty = tk.Text(nwin, width=300, height=300, wrap=tk.WORD)
enty = tk.Entry(nwin)
enty.pack(side=tk.LEFT, fill=None)
btn = tk.Button(nwin, text='確認', command=getv)
btn.pack(side=tk.LEFT, padx=6, ipadx=6)
enty.insert('end', ttext[colint-1]) # 編輯框顯示值
openwin.append(nwin)
# if len(openwin) > 1:
# openwin.pop(0).destroy()
# nwin.protocol('WM_DELETE_WINDOW', initopenwin) # 繫結時件,關閉窗清除變數值
# nwin.mainloop()
def getv():
global nwin
global enty
global tree
global sitem
global colint
global openwin
editxt = enty.get()
tree.set(sitem, (colint-1), editxt)
openwin = []
nwin.destroy()
def savebook():
global w
global tree
global titles
global savepath
ws = w.create_sheet('change1')
ws.append(titles)
for itm in tree.get_children():
ws.append(tree.item(itm)['values'])
w.save(savepath)
# messagebox.showinfo('提示', '儲存成功')