Skip to main content

Python Excel to Json

Project description

python_excel2json

A simple way to parse an excel file and get the json that you want.

Install

pip install python_excel2json

Dependencies

xlrd

Usage

from python_excel2json import parse_excel_to_json

# Step 1: Define the format of your excel that you want to parse.

excel_sheets_format = {
    'start_row_sheet_parsing': 1,
    'start_column_sheet_parsing': 0,
    'sheet_formats': [
        {
            'sheet_index': 0,
            'column_names': [
                {
                    'name': 'name1',
                    'type': 'str'
                },
                {
                    'name': 'name2',
                    'type': 'str'
                },
                {
                    'name': 'name3',
                    'type': 'str'
                },
                {
                    'name': 'name4',
                    'type': 'float'
                }
            ],
            'is_ordered': True
        },
        {
            'sheet_index': 1,
            'column_names': [
                {
                    'name': 'name1',
                    'type': 'str'
                },
                {
                    'name': 'name2',
                    'type': 'str'
                },
                {
                    'name': 'name3',
                    'type': 'str'
                },
                {
                    'name': 'name4',
                    'type': 'float'
                }
            ],
            'is_ordered': True,
            'start_row_sheet_parsing': 3,
            'start_column_sheet_parsing': 5
        }
    ]
}

# Step 2: Define your excel file input. Using 'xlrd' it can be from two ways:

file = '/my/path/my-file.xlsx'
result = parse_excel_to_json(excel_sheets_format, filename=file)

file = your-excel-content
result = parse_excel_to_json(excel_sheets_format, file_contents=file)

# Step 3: Obtain your specific json result.

[
    {
        'sheet_index': 0,
        'results': [
            {
                'name1': 'value',
                'name2': 'value',
                'name3': 'value'
            },
            ...
        ]
    },
    {
        'sheet_index': 1,
        'results': [
            {
                'name1': 'value',
                'name2': 'value',
                'name3': 'value',
                'name4': 'value'
            },
            ...
        ]
    }
]

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

python_excel2json-0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file python_excel2json-0.1-py3-none-any.whl.

File metadata

  • Download URL: python_excel2json-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for python_excel2json-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d22956590173f249e365929f4a1378f791fe5ec0ac09dc5a2f74a2759bd4f78
MD5 f9033ba5bc031528d79c0157e2fa513b
BLAKE2b-256 bdffb689b03aa415ebef6ff3320b2e075fc0a97657eac136415fa70a7c524328

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