Skip to main content

hfexcel 0.0.17 CircleCI codecov

human friendly excel creation in python

development versions of dependencies

  • Python 3.x
  • XlsxWriter==1.1.8
  • jsonschema==2.6.0
  • pytest
  • codecov
  • pytest-cov

install

pip install hfexcel

features

  • Human readable coding, building
  • Object-Obriented based readable models: HFExcelWorkbook, HFExcelSheet, HFExcelColumn, HFExcelColumn
  • HFExcelWorkbookFilter: Helper class to populate Excel from a JSON data (python dict) with a pre-defined json schema. (default:hfexcel.schemas.DEFAULT_SCHEMA)
  • HFExcelWorkbook.output: Output creation on filename (string) input being null, and created output parameter with the type BytesIO linked to workbook itself

playground

example of converting nested objects {sheet>column>row} input from json format into excel format

from hfexcel import HFExcel
from hfexcel.schemas import DEFAULT_SCHEMA


excel_data = {
    "sheets": [
        {
            "key": "sheet1",
            "name": "Example Sheet 1",
            "columns": [
                {
                    "name": "Column 1",
                    "width": 2,
                    "args": [
                        "headline"
                    ],
                    "rows": [
                        {
                            "data": "Column 1 Row 1"

                        },
                        {
                            "data": "Column 1 Row 2"
                        }
                    ]
                },
                {
                    "name": "Column 2",
                    "rows": [
                        {
                            "data": "Column 2 Row 1",
                        },
                        {
                            "data": "Column 2 Row 2",
                        }
                    ]
                },
                {
                    "name": "Column 3",
                    "rows": [
                        {
                            "data": "Column 3 Row 1"
                        },
                        {
                            "data": "Column 3 Row 2"
                        }
                    ]
                }
            ]
        }
    ],
    "styles": [
        {
            "name": "headline",
            "style": {
                "bold": 1,
                "font_size": 14,
                "font": "Arial",
                "align": "center"
            }
        }
    ]
}

hf_workbook = HFExcel.hf_workbook('example.xlsx', set_default_styles=False)
hf_workbook.filter().populate_with_json(excel_data, schema=DEFAULT_SCHEMA)
hf_workbook.save()

example of object-oriented python syntax

from hfexcel import HFExcel

hf_workbook = HFExcel.hf_workbook('example.xlsx', set_default_styles=False)

hf_workbook.add_style(
    "headline", 
    {
        "bold": 1,
        "font_size": 14,
        "font": "Arial",
        "align": "center"
    }
)

sheet1 = hf_workbook.add_sheet("sheet1", name="Example Sheet 1")

column1, _ = sheet1.add_column('headline', name='Column 1', width=2)
column1.add_row(data='Column 1 Row 1')
column1.add_row(data='Column 1 Row 2')

column2, _ = sheet1.add_column(name='Column 2')
column2.add_row(data='Column 2 Row 1')
column2.add_row(data='Column 2 Row 2')


column3, _ = sheet1.add_column(name='Column 3')
column3.add_row(data='Column 3 Row 1')
column3.add_row(data='Column 3 Row 2')

# In order to get a row with coordinates:
# sheet[column_index][row_index] => row
print(sheet1[1][1].data)
assert(sheet1[1][1].data == 'Column 2 Row 2')

hf_workbook.save()

example of converting inline index-based {sheet>[column:row]} input from json format into excel format

from hfexcel import HFExcel
from hfexcel.extras import InlineInputHelper

excel_data = {
    "sheets": [
        {
            "key": "sheet1",
            "name": "Example Sheet 1",
            "columns": [
                {
                    "name": "Column 1",
                    "width": 2,
                    "args": [
                        "headline"
                    ]
                },
                {
                    "name": "Column 2"
                }
            ],
            "rows": [
                [
                    {
                        "data": "Column 1 Row 1"

                    },
                    {
                        "data": "Column 2 Row 1"
                    }
                ],
                [
                    {
                        "data": "Column 1 Row 2"

                    },
                    {
                        "data": "Column 2 Row 2"
                    }
                ]
            ]
        }
    ],
    "styles": [
        {
            "name": "headline",
            "style": {
                "bold": 1,
                "font_size": 14,
                "font": "Arial",
                "align": "center"
            }
        }
    ]
}

hf_workbook = HFExcel.hf_workbook(filename, set_default_styles=False)
InlineInputHelper(hf_workbook).populate_with_json(excel_data)
hf_workbook.save()
return True

example output file

contributors

  • @ebsaral - author
  • feel free to contribute

dependencies

warning

  • Happy path tests are written.

Release files for hfexcel 0.0.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hfexcel 0.0.17
File Size Uploaded
hfexcel-0.0.17.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hfexcel 0.0.17
File Interpreter ABI Platform
hfexcel-0.0.17-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / hfexcel-0.0.17.tar.gz

Download URL hfexcel-0.0.17.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6542939750b803c00d5611a1171b1863a1ec1a98ca17a86dfaff5ee7715a4c67
BLAKE2b-256 checksum
How to use checksums
67ddd9ee9b05a3ac0586b3f212c6a045ceb8b01856c4235250764c59ddf16a6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

Release files / hfexcel-0.0.17-py3-none-any.whl

Download URL hfexcel-0.0.17-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c63c1ac6dec33fc74ebe47ba9016c198f817356459e0676d823316721ff94563
BLAKE2b-256 checksum
How to use checksums
ec38bbc42042ba0879be9f9a86637a167007f4ec7f1172da426931c1c54a65aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.0.17 This release

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page