我想在excelfile中打印python脚本的输出。我试过这段代码,但它从选定的输入文件中读取每一行,然后将其写入一个名为output.xls的新excel文件中?谢谢在excel中打印python脚本输出
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()
你说的'打印python脚本的输出excelfile'是什么意思?而上述是如何不是**你想要什么? –