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:C28 >>> 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:
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]]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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xlref-1.2.3.tar.gz
.
File metadata
- Download URL: xlref-1.2.3.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0bc79b1f61760b558c60a94233d28e7edbda893e3ad226cbd816f406b545d6e |
|
MD5 | 548660bba52881d0cb77502f01adf06a |
|
BLAKE2b-256 | 90b71c7c3078a6fe24fe08adfc69a91f58d3551f5a5d82dc88a4ad33233f29d2 |
File details
Details for the file xlref-1.2.3-py2.py3-none-any.whl
.
File metadata
- Download URL: xlref-1.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eedd98cc2b17bbc368e2cfc16bacddba53e0f1fc7a6b8f37ac590c800f6971c6 |
|
MD5 | 6748c176c0db3d7df29920435f71849a |
|
BLAKE2b-256 | 46175c75474f283568bd4aaa40b5b103c297ec9827d0ab3d2a9ad1b79d53a533 |