import os
import xlwt
def save_to_excel(check_date, data):
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
for sheet_name, item in data.items():
sheet = book.add_sheet(sheet_name, cell_overwrite_ok=True)
for i in range(0, len(item)): # 写入字段信息
for j in range(0, len(item[i])):
sheet.write(i, j, str(item[i][j]))
# 记住要保存
filename = '{}-long-bill.xls'.format(check_date)
filepath = '/Users/dzsbamacbookair/Desktop/script/lianxi/{}'.format(filename)
book.save(filepath)
# if os.path.exists(filepath) and os.path.isfile(filepath): # 检测文件是已经存在
# os.remove(filepath) # 删除文件
if __name__ == '__main__':
save_to_excel('20210710',{'通道长单': [['主播', '诨名', '性别'],['卢本伟', '55开', '神'],['赵梦玥', '一血妹', '女']]})