#(1)引入模块
import xlwt
#(2)2工作簿
wb = xlwt.Workbook()
#(3)表
sheet = wb.add_sheet(“商品列表”)
productList = [{
“sku”: 1,
“name”: “iphone 12 pro max”,
“price”: 12999,
“brand”: “苹果”
}, {
“sku”: 2,
“name”: “mate 40”,
“price”: 7999,
“brand”: “华为”
}, {
“sku”: 3,
“name”: “vivo r9”,
“price”: 3999,
“brand”: “vivo”
}]
list = [“sku”,“name”,“price”,“brand”]
for (i,v) in enumerate(list):
sheet.write(0,i,v)
def priductlist(args):
pass
for (i,v) in enumerate(productList):##行
for(j,k) in enumerate(list):
#第 i + 1(头) 行; 第j列
#值 v(字典)中,k头就是键v[k]
sheet.write(i + 1, j, v[k])
#保存
wb.save(“马冬梅1.xls”)