{"id":15683789,"url":"https://github.com/dxe4/jsontoxls","last_synced_at":"2025-05-07T14:24:12.637Z","repository":{"id":8666347,"uuid":"10322292","full_name":"dxe4/jsonTOxls","owner":"dxe4","description":"Create Excel files using json requests using tornado (optional) and XlsxWriter.","archived":false,"fork":false,"pushed_at":"2013-10-10T23:15:40.000Z","size":856,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T14:24:07.787Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dxe4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-27T20:45:24.000Z","updated_at":"2024-08-12T03:21:56.000Z","dependencies_parsed_at":"2022-07-08T06:20:48.645Z","dependency_job_id":null,"html_url":"https://github.com/dxe4/jsonTOxls","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxe4%2FjsonTOxls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxe4%2FjsonTOxls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxe4%2FjsonTOxls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxe4%2FjsonTOxls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dxe4","download_url":"https://codeload.github.com/dxe4/jsonTOxls/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252892954,"owners_count":21820739,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T17:08:35.860Z","updated_at":"2025-05-07T14:24:12.615Z","avatar_url":"https://github.com/dxe4.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=========\njsonTOxls\n=========\n\nCreate Excel files using json requests. Send json to create xls,xlsx files using XlsxWriter (https://github.com/jmcnamara/XlsxWriter).\nYou can optionally run a tornado server to accept the requests.\n\nIt works as basic functionality (add values, sheets, formats, conditional formatting, merging)\n___\n#Requires\n\n    python3 (may work with 2 as well)\n    and the libraries mentioned above\n\n#To run\n\n    server (optional) : python3 jsonTOxls_server.py\n    python3 jsonTOxls.py (will run example 4)\n\n    if you want to run different examples run :\n        python3 jsonTOxls.py 1\n        python3 jsonTOxls.py 2\n        python3 jsonTOxls.py 3\n        python3 jsonTOxls.py 4\n\n#Documentation\n\nFor input documentation used to create files you can check xlsxwritter documentation at:https://xlsxwriter.readthedocs.org/en/latest/ \n\n\nExample 1:\n---\nJust a \"Hello World example\".\n\n     -The json contains a list of sheets.\n     -Each sheet is a dictionary sheet name to data\n___\n```python\n     sheet_data = {\n        'A1': 'Item',\n        'B1': 'Cost',\n        #\n        'A2': 'Rent',\n        'A3': 'Gas',\n        'A4': 'Food',\n        'A5': 'Gym',\n        'A6': 'Total',\n        #\n        'B2': '10.10',\n        'B3': '100.1',\n        'B4': '300.5',\n        'B5': '50.0',\n        'B6': '=SUM(B1:B4)'\n    }\n\n    sheet = {\n        'sheets': [\n            {\"Test Sheet\": sheet_data}\n        ]\n    }\n```\nExample 1 Output:\n---\n![alt text](https://raw.github.com/papaloizouc/jsonTOxls/master/examples/images/example1.png \"Example 1\")\n___\nExample 2:\n---\nFormats \n      \n    -Json structure: {'sheets' : list of sheets, 'formats': dict of formats}\n    -You can use either A1 or 0,0 it gives the same result\n    -You can also use either '0,0':'Foo' or '0,0':{'value':'Foo','format':'the_format'}\n    -For more about formats check the xlsxWritter doc\n___\n```python\n   sheet_data = {\n        'A1': {'value': 'Item', 'format': 'bold'},\n        'B1': {'value': 'Cost', 'format': 'bold'},\n        #\n        '1,0': 'Rent',\n        '2,0': 'Gas',\n        '3,0': 'Food',\n        '4,0': 'Gym',\n        '5,0': 'Total',\n        #\n        '1,1': {'value': '50.50', 'format': 'number_bold_red'},\n        '2,1': {'value': '15.88', 'format': 'number_bold_red'},\n        '3,1': {'value': '33.90', 'format': 'number_bold_red'},\n        '4,1': {'value': '80.55', 'format': 'number_bold_red'},\n        '5,1': {'value': '=SUM(B2:B5)', 'format': 'number_bold_red'}\n    }\n\n    sheet = {\n        'sheets': [\n            {\"Test Sheet\": sheet_data},\n        ],\n        \"formats\": {\n            'bold': {'bold': True},\n            'bold_red': {'bold': True, 'font_color': 'red'},\n            #\n            'number': {'num_format': '$#,##.##'},\n            'number_bold_red': {'bold': True, 'font_color': 'red', 'num_format': '$#,##.##'},\n            'number_bold_blue': {'bold': True, 'font_color': 'red', 'bg_color': '#99CCFF', 'num_format': '$#,##.##'},\n        }\n    }\n```\nExample 2 Output:\n---\n![alt text](https://raw.github.com/papaloizouc/jsonTOxls/master/examples/images/example2.png \"Example 2\")\n___\n\nExample 3:\n---\n     -Resize is inside the sheet data because different sheets may have different column sizes, same for conditional formatting.\n___\n```python\n     sheet_data = {\n        'A1': {'value': 'Item', 'format': 'bold'},\n        'B1': {'value': 'Cost', 'format': 'bold'},\n        'C1': {'value': 'Date', 'format': 'bold'},\n        #\n        '1,0': 'Rent',\n        '2,0': 'Gas',\n        '3,0': 'Food',\n        '4,0': 'Gym',\n        '5,0': 'Total',\n        #\n        '1,1': {'value': '500.50', 'format': 'number_bold_red'},\n        '2,1': {'value': '150.88', 'format': 'number_bold_red'},\n        '3,1': {'value': '330.90', 'format': 'number_bold_red'},\n        '4,1': {'value': '80.55', 'format': 'number_bold_red'},\n        '5,1': {'value': '=SUM(B2:B5)', 'format': 'sum_format'},\n        #\n        '1,2': {'date': '2013-01-01', 'format': 'date_format'},\n        '2,2': {'date': '2013-02-01', 'format': 'date_format'},\n        '3,2': {'date': '2013-03-01', 'format': 'date_format2'},\n        '4,2': {'date': '2013-04-01', 'format': 'date_format2'},\n        #\n\n\n        \"conditional_formats\": {\n            'B2:B5': {\n                'type': 'cell', 'criteria': '\u003e=', 'value': 300, 'format': 'number_bold_blue'\n            }\n        },\n        #\n        \"column_size\": {\n            'A:B': 15,\n            'C:C': 25\n        }\n    }\n\n    sheet = {\n        'sheets': [\n            {\"Test Sheet\": sheet_data},\n        ],\n        \"formats\": {\n            'bold': {'bold': True},\n            'bold_red': {'bold': True, 'font_color': 'red'},\n            #\n            'number': {'num_format': '$#,##.##'},\n            'number_bold_red': {'bold': True, 'font_color': 'red', 'num_format': '$#,##.##'},\n            'number_bold_blue': {'bold': True, 'font_color': 'red', 'bg_color': '#99CCFF', 'num_format': '$#,##.##'},\n            #\n            'sum_format': {'bold': True, 'bg_color': '#E9AA94'},\n            'date_format': {'num_format': 'yyyy d mmmm'},\n            'date_format2': {'num_format': 'yy dd mmm'}\n        }\n    }\n```\nExample 3 Output:\n---\n![alt text](https://raw.github.com/papaloizouc/jsonTOxls/master/examples/images/example3.png \"Example 3\")\n___\n\n\nExample 4:\n--- \nThis example is very big but the generated json and xls file is in the project examples folder.\n\nMerge\n---\nTo merge use this:\n     \n     A1-D1:'merged region'\n\nProgress\n---\nYou can check PROGRESS.txt for implemented functionality, coming functionality and known issues.\n\nMotivation: Why do we need this anyway?\n---\n1) Unified approach, It's not specific to your programming language (if you run tornado).\n\n2) Abstraction: Chunking Up from excel specific code as shown in 3 to json dicts lists\n\n3) Personally i dislike report code, hence this pseudo code example*:\n```python\n     rowIndex, colIndex = 1,0\n     row = sheet.createRow(rowIndex)\n     cell = row.createCell(colIndex)\n     cell.setValue(values[(rowIndex,colIndex)])\n     cell.setStyle(styles[(rowIndex,colIndex)])\n```\nChanges to:\n```python\n     row,col = 1,0\n     sheet[str(row) + \",\" + str(col)] = {\n               \"value\":values[(row,col)],\n               \"format\":formats[(row,col)]\n     }\n```\nAnd with some imagination:\n```python\n     row,col = 1,0\n     key = lambda row,col: str(row) + \",\" + str(col)\n     val = lambda row,col:(\n              {\n                 \"value\":values[(row,col)],\n                  \"format\":formats[(row,col)]\n              }\n     )\n     sheet[key(row,col)] = val(row,col)\n```\n*Note i didn't run this code, I just wrote it in the readme file to demonstrate an example.\n\n4) And you end up applying divide and conquer technique for the problem which is now split in 4 steps: \n     \n     - Fetch data\n     - Process data (decide which cells hold which values - create values and formats dictionaries)\n      -Create json as shown above\n      -Send json to create xls without writing code\n\nI will try to demonstrate this in the up-coming Exmaple 5 because theory is easier than practice (sometimes).\n     \nFeedback\n---\nIf you disagree with anything or want to request a feature feel free: ANY feedback is much appreciated as well as criticism. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdxe4%2Fjsontoxls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdxe4%2Fjsontoxls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdxe4%2Fjsontoxls/lists"}