用xlwt模塊執行代碼報下面的錯
ValueError: column index (256) not an int in range(256)
xlwt 模塊看源碼說最大列只支持255列,所以超過這個值就報錯了,改用xlsxwriter模塊
import xlsxwriter workbook = xlsxwriter.Workbook('chineseQA.xlsx') #創建工作簿 worksheet = workbook.add_worksheet() #創建工作表 title=['question','answer'] lie = 0#定義要插入的列,0是第一列 for i in title: worksheet.write(0,lie,i) lie+=1 hang = 1#定義要插入的行,1是第二行 with open('question',encoding='utf-8') as f: lie1 = 0#定義要插入的列 for i in f.readlines(): lis=i.strip() worksheet.write(hang, lie1, lis) hang+=1#行數加一 lie1+=1#列數加一 hang=1 with open('answer',encoding='utf-8') as f: lie1 = 1 for i in f.readlines(): lis=i.strip() worksheet.write(hang, lie1, lis) hang+=1 lie1+=1 workbook.close()
參考下面這篇博客
http://www.mamicode.com/info-detail-2252921.html