废话不多说,直接开干!
之前只能导出单行数据,没法循环导出
import datetime
import time
import pymysql
import xlwt
def write_excel(res):
update_time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
book = xlwt.Workbook() # 创建一个excel
sheet = book.add_sheet("2021商品话单")
title = ['sku数据', '评价数量']
i = 0
for header in title:
sheet.write(0, i, header)
i += 1
# 写入数据
for row in range(1, len(res)):
li = res[row].split("-")
sheet.write(row, 0, li[0])
sheet.write(row, 1, li[1])
# row+=1
# print(row)
book.save('文件名字{}.xlsx'.format(update_time))
print("导出成功!")
# read_excel()
if __name__ == '__main__':
data = ['42151458065-0', '42151458066-0', '42151458067-0', '42151458068-0']
write_excel(data)