我想在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'是什麼意思?而上述是如何不是**你想要什麼? –