如果我有幾個數組,我想用Python寫入一個excel文件,那麼最好的方法是什麼?我嘗試了幾種方法,並不能弄明白....這是林很新的這如何將幾個數組寫入excel文件?
import xlwt
from tempfile import TemporaryFile
book = xlwt.Workbook()
sheet1 = book.add_sheet('sheet1')
a=[1,2,3,4,5]
b=[6,7,8,9,10]
c=[2,3,4,5,6]
data = [a,b,c]
for i,e in enumerate(data):
sheet1.write(i,1,e)
name = "this.xls"
book.save(name)
book.save(TemporaryFile())
你的數據有兩個維度,這表明你需要一個嵌套循環。對於行,枚舉(數據)中的數組:col,枚舉(數組)中的值:sheet.write(row,col,value)'或類似的東西。 –