我正在尝试编写一个 python 脚本来:
我很新,正在努力让它工作。
import json
import xlwt
# Workbook is created
wb = xlwt.Workbook()
# add_sheet is used to create sheet.
sheet1 = wb.add_sheet('Sheet 1')
# open json file and store it in data variable
with open('input.json') as f:
data = json.load(f)
# write the column names in the excel sheet
sheet1.write(0, 0, 'Name')
sheet1.write(0, 1, 'Schedule')
sheet1.write(0, 2, 'Time Window')
sheet1.write(0, 3, 'Type')
sheet1.write(0, 4, 'Tiers')
# iterate over the data and write it to the excel file
row = 1;
for item in data:
#write each value to the corresponding column
sheet1.write(row, 0, item['Name'])
sheet1.write(row, 1, item['Schedule'])
sheet1.write(row, 2, item['Time Window'])
sheet1.write(row, 3, item['Type'])
sheet1.write(row, 4, item['Tiers'])
row += 1;
#save the file
wb.save('data_converted_to_excel.xls')
我试过用 项目 = json.loads(项目) 但一直无法让它工作。
我是初学者。对不起!