import json import xlwt biaotou='[{"name_cn":"企业名称","name_en":"QYMC"},{"name_cn":"类别","name_en":"LB"},{"name_cn":"地市","name_en":"DS"},{"name_cn":"批次","name_en":"PC"}]'; datas='[{"PC":"第一批","LB":"专精特新工业","QYMC":"某某有限公司","DS":"济南"}]' def getDate(): print("来萨博 biaotou datas") # 创建一个workbook 设置编码 workbook = xlwt.Workbook(encoding='utf-8') # 创建一个worksheet worksheet = workbook.add_sheet('My Worksheet1') mes_to_dict = json.loads(biaotou) for index,item, in enumerate(mes_to_dict): # 参数对应 行, 列, 值 worksheet.write(1, index, label=item['name_cn']) datas_json = json.loads(datas) for index,item in enumerate(datas_json): print(index,item) worksheet.write(index+2, 0, label=item['PC']) worksheet.write(index+2, 1, label=item['LB']) worksheet.write(index+2, 2, label=item['QYMC']) worksheet.write(index+2, 3, label=item['DS']) # 保存 workbook.save('Excel_test2.xls') if __name__ == '__main__': getDate(); ———————————————— 版权声明:本文为CSDN博主「飞飞翼」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_36935391/article/details/127728320
标签:index,name,python,worksheet,Excel,label,item,json From: https://www.cnblogs.com/xiguanchenmo/p/17126444.html