Skip to main content

Creates xlsx from json via openpyxl.

Project description

xlsx_from_json

Creates xlsx from json via openpyxl.

Usage

Create .json file with following structure:

{
    "rows": [
        {
            "cells": [
                {
                    "value": "Sample text",
                    // merge 5x2 cell range
                    "width": 5,
                    "height": 2,
                    // openpyxl style: https://openpyxl.readthedocs.io/en/2.5/styles.html
                    "style": {
                        "font": {
                            "name": "Times New Roman",
                            "size": 12
                        },
                        "border": {
                          "bottom": {
                            // openpyxl border styles: // https://openpyxl.readthedocs.io/en/stable/_modules/openpyxl/styles/borders.html
                            "border_style": "medium",
                            "color": "FFFFFFFF"
                          }
                        }
                    }
                }
            ],
            // move row by 2x1
            "skip_columns": 2,
            "skip_rows": 1,
            // change row height
            "row_height": 10
        }
    ],
    "start_column": 1,
    "start_row": 1,
    // change column widths
    "column_widths": [
        {
            // column_number or column_letter
            "column_number": 1,
            "width": 10
        }
    ],
    // set number format (e.g. 1.234 -> 1.23)
    "number_format": "0.00",
    // apply style to all cells
    "default_style": {
        "font": {
            "bold": true
        }
    }
}

Create openpyxl workbook via xlsx_from_json function:

import json
from xlsx_from_json import xlsx_from_json

with open("data.json", encoding="utf-8") as f:
    json_data = json.load(f)

wb = xlsx_from_json(json_data)

Created workbook will have values:

sheet = wb.active
assert sheet.cell(row=2, cell=3).value == "Sample text"

The same true for the styles (cell ctyle + default style):

sheet = wb.active
assert sheet.cell(row=2, cell=3).font.name == "Times New Roman"
assert sheet.cell(row=2, cell=3).font.bold == True

Now you can use workbook according to openpyxl guide.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xlsx_from_json-1.0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

xlsx_from_json-1.0.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file xlsx_from_json-1.0.1.tar.gz.

File metadata

  • Download URL: xlsx_from_json-1.0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for xlsx_from_json-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3ff087e8e775ce0c5058661c303c59939346485ae49268f495129bbea0d07216
MD5 de4420604a8615c89aa0e8a5fabbaf7c
BLAKE2b-256 09067d4e9ce23bc37c9bae48c751e44c80d42eecca2e415f1afbeee83d959ef4

See more details on using hashes here.

File details

Details for the file xlsx_from_json-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: xlsx_from_json-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for xlsx_from_json-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e389cd487b82d75698400a266057358de4f66b0aea5ac28cc62e5493e7f771f5
MD5 1213fc59366359345c73fbf188a90a63
BLAKE2b-256 2d3cf483e314f00719da73923abbac3570f2cf80e36dfe895d8dc2b926b79e60

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page