程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] invalid solution of saving excel file with xlwt

編輯:Python

Take a brief look at the code  

def write2Excel(INFO, excel_path, sheet_name):
keys = list(INFO.keys()) # Get dictionary's key value
values = list(INFO.values()) # Get dictionary's value value
# print(keys)
# print(values)
book = xlwt.Workbook()
sheet = book.add_sheet(sheet_name)
# Write column name
for i in range(0, len(keys)):
sheet.write(0, i, keys[i])
# Write data
for j in range(0, len(values)):
sheet.write(1, j, values[j])
book.save(excel_path)
# Execution time
write2Excel(INFO, './Result/excel_02.xlsx', 'Sheet1')

The problem is : Invalid file format or file extension

It's very strange , do not know why , Then I found someone else's solution , Change the execution statement to :

write2Excel(INFO, './Result/excel_02.xls', 'Sheet1')

  namely , hold .xlsx Replace the file with .xls  File extension is ok .

Close test effectively , But I still don't understand why , First bury a pit , Then come back when you understand Update the answer .

If anyone who knows about it passes by and shares the reason for this problem , Thank you for .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved