简单看看一下代码
def write2Excel(INFO, excel_path, sheet_name): keys = list(INFO.keys()) # 获取字典的key值 values = list(INFO.values()) # 获取字典的value值 # print(keys) # print(values) book = xlwt.Workbook() sheet = book.add_sheet(sheet_name)
# 写入列名
for i in range(0, len(keys)):
sheet.write(0, i, keys[i])
# 写入数据
for j in range(0, len(values)):
sheet.write(1, j, values[j])
book.save(excel_path)
#执行时 write2Excel(INFO, './Result/excel_02.xlsx', 'Sheet1')
遇到问题是:文件格式或文件扩展名无效
特别奇怪,不知道为什么,然后找到了别人的解决办法,把执行语句改成:
write2Excel(INFO, './Result/excel_02.xls', 'Sheet1') 即,把 .xlsx 的文件换成 .xls 文件扩展名即可。
标签:INFO,xlwt,sheet,keys,excel,book,values,报错 From: https://blog.51cto.com/u_15692628/6096559