Skip to main content

human friendly excel creation in python

Project description

hfexcel 0.0.15 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

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()

or

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 output file

contributors

  • @ebsaral - author
  • feel free to contribute

dependencies

warning

  • Happy path tests are written.

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

hfexcel-0.0.15.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

hfexcel-0.0.15-py3-none-any.whl (10.4 kB view hashes)

Uploaded Python 3

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