Calculate XLSX formulas
Project description
Calculate XLSX formulas
xlsx_evaluate - python library to convert excel functions in python code without the need for Excel itself within the scope of supported features.
This library is fork xlcalculator. Use this library.
Summary
- Currently supports
- Supported Functions
- Adding/Registering Excel Functions
- Excel number precision
- Test
Installation
# pip
pip install xlsx-evaluate
# poetry
poetry add xlsx-evaluate
Example
input_dict = {
'B4': 0.95,
'B2': 1000,
"B19": 0.001,
'B20': 4,
'B22': 1,
'B23': 2,
'B24': 3,
'B25': '=B2*B4',
'B26': 5,
'B27': 6,
'B28': '=B19 * B20 * B22',
'C22': '=SUM(B22:B28)',
}
from xlsx_evaluate import ModelCompiler
from xlsx_evaluate import Evaluator
compiler = ModelCompiler()
my_model = compiler.read_and_parse_dict(input_dict)
evaluator = Evaluator(my_model)
for formula in my_model.formulae:
print(f'Formula {formula} evaluates to {evaluator.evaluate(formula)}')
# cells need a sheet and Sheet1 is default.
evaluator.set_cell_value('Sheet1!B22', 100)
print('Formula B28 now evaluates to', evaluator.evaluate('Sheet1!B28'))
print('Formula C22 now evaluates to', evaluator.evaluate('Sheet1!C22'))
TODO
-
Do not treat ranges as a granular AST node it instead as an operation ":" of two cell references to create the range. That will make implementing features like
A1:OFFSET(...)
easy to implement. -
Support for alternative range evaluation: by ref (pointer), by expr (lazy eval) and current eval mode.
-
Pointers would allow easy implementations of functions like OFFSET().
-
Lazy evals will allow efficient implementation of IF() since execution of true and false expressions can be delayed until it is decided which expression is needed.
-
-
Implement array functions. It is really not that hard once a proper RangeData class has been implemented on which one can easily act with scalar functions.
-
Improve testing
-
Refactor model and evaluator to use pass-by-object-reference for values of cells which then get "used"/referenced by ranges, defined names and formulas
-
Handle multi-file addresses
-
Improve integration with pyopenxl for reading and writing files example of problem space
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 xlsx_evaluate-0.2.0.tar.gz
.
File metadata
- Download URL: xlsx_evaluate-0.2.0.tar.gz
- Upload date:
- Size: 41.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/35.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.4 keyring/23.5.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7108868b2b088af04482590226376c26e349934dee5d98c8dcf72dc8a2630b1 |
|
MD5 | 07bd1a7f92eb8f25d36e49bbac274150 |
|
BLAKE2b-256 | b59841bb26271603b102a00113c9b960b20b6a8ecb0b02aa71d5ae40408edcad |
File details
Details for the file xlsx_evaluate-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: xlsx_evaluate-0.2.0-py3-none-any.whl
- Upload date:
- Size: 47.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/35.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.4 keyring/23.5.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c662f5eb453a55ecb1869a08b70d4cefc2c85672a1448bcda7b89ce299c1dcf5 |
|
MD5 | bebfe70b5328fb46804a56d65d948fc6 |
|
BLAKE2b-256 | 6b1c7d56d213705489dc103cdabaaf035fce2bd0926b38caf3757c21fffc8987 |