我想在 excelfile 中打印 python 脚本的输出。我尝试了这段代码,但它从选定的输入文件中读取每一行,然后将其写入一个名为 output.xls 的新 Excel 文件?谢谢你
import xlwt
from Tkinter import *
from tkFileDialog import askopenfilename
def callback():
filename = askopenfilename()
wb = xlwt.Workbook()
ws0 = wb.add_sheet('Sheet1')
with open(filename, 'r') as f:
for i, line in enumerate(f):
ws0.write(i, 0, line.strip())
wb.save('output.xls')
errmsg = 'Error!'
a = Button(text='click me', command=callback)
a.pack()
mainloop()