Last active
January 14, 2024 10:33
-
-
Save patmandenver/101ca2429a9abdbe8043eaa1d7afee3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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