#!/usr/bin/env python3 | |
import openpyxl | |
import json | |
from openpyxl import Workbook | |
############################################# | |
# MAIN | |
############################################# | |
if __name__ == '__main__': | |
json_data = {} | |
with open("original.json") as json_file: | |
json_data = json.load(json_file) | |
wb = Workbook() | |
# grab the active worksheet | |
ws_01 = wb.active | |
#Set the title of the worksheet | |
ws_01.title = "First Sheet" | |
#Set first row | |
ws_01.cell(1,1, "Month") | |
ws_01.cell(1,2, "food") | |
ws_01.cell(1,3, "heating") | |
ws_01.cell(1,4, "rent") | |
row = 1; | |
for month in json_data.keys(): | |
row+=1 | |
ws_01.cell(row,1, month) | |
ws_01.cell(row,2, float(json_data[month]["food"])) | |
ws_01.cell(row,3, float(json_data[month]["heating"])) | |
ws_01.cell(row,4, float(json_data[month]["rent"])) | |
#Save it in an Excel fie | |
wb.save("test_json.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment