Skip to main content

Excel table reader library.

Project description

About xlref

xlref is an useful library to capture by a simple reference (e.g., A1(RD):..:RD) a table with non-empty cells from Excel-sheets when its exact position is not known beforehand.

This code was inspired by the xleash module of the pandalone library. The reason of developing a similar tool was to have a smaller library to install and improve the performances of reading .xlsx files.

Installation

To install it use (with root privileges):

$ pip install xlref

Or download the last git version and use (with root privileges):

$ python setup.py install

Tutorial

A typical example is capturing a table with a “header” row and convert into a dictionary. The code below shows how to do it:

>>> import xlref as xl
>>> _ref = 'excel.xlsx#ref!A1(RD):RD[%s]'
>>> ref = xl.Ref(_ref % '"dict"')
>>> ref.range  # Captured range.
B2:C25
>>> values = ref.values; values  # Captured values.
{...}
>>> values['st-cell-move']
'#D5(RU):H1(DL)'

You can notice from the code above that all the values of the dictionary are references. To parse it recursively, there are two options:

  1. add the “recursive” filter before the “dict”:

    >>> values = xl.Ref(_ref % '"recursive", "dict"').values
    >>> values['st-cell-move'].tolist()
    [[1.0, 2.0, 3.0],
     [4.0, 5.0, 6.0],
     [7.0, 8.0, 9.0]]
    
  2. apply a filter onto dictionary’ values using the extra functionality of the “dict” filter:

    >>> values = xl.Ref(_ref % '{"fun": "dict", "value":"ref"}').values
    >>> values['st-cell-move'].tolist()
    [[1.0, 2.0, 3.0],
     [4.0, 5.0, 6.0],
     [7.0, 8.0, 9.0]]
    

You have also the possibility to define and use your custom filters as follows:

>>> import numpy as np
>>> xl.FILTERS['my-filter'] = lambda parent, x: np.sum(x)
>>> xl.Ref('#D5(RU):H1(DL)["my-filter"]', ref).values
45.0

An alternative way is to use directly the methods of the filtered results as follows:

>>> xl.Ref('#D5(RU):H1(DL)["sum"]', ref).values
45.0

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

xlref-1.1.2.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

xlref-1.1.2-py2.py3-none-any.whl (17.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file xlref-1.1.2.tar.gz.

File metadata

  • Download URL: xlref-1.1.2.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for xlref-1.1.2.tar.gz
Algorithm Hash digest
SHA256 dd5d7e4722e455938143de363a27d3023dc2a05dd23b1cf59477bf62047aef92
MD5 6e3dc3da784923a797ba7aeb0f604f7f
BLAKE2b-256 271a8de0d53c4a41e4bb4fdfe0e3498e811deec88f707e2da85a173db9b32bc2

See more details on using hashes here.

File details

Details for the file xlref-1.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: xlref-1.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for xlref-1.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d953b162525a7138283fcdc8e22f6cffba8ce2729d0c5b7f36cd1413b3fdaf74
MD5 b8570d3667757b99e64d1a4fb9107533
BLAKE2b-256 b729c177381bd2561eda2e7a2d1e9fa9c567ac0fd76dd92512118cd3d16bbf44

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