Skip to main content

Calculate XLSX formulas

CI Coverage Status PyPI version License: MIT

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

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)',
    "D1": "abc",
    "D2": "bca",
    "D3": "=CONCATENATE(D1, D2)",
  }

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'))
print('Formula D3 now evaluates to', evaluator.evaluate("Sheet1!D3"))

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

Metadata

Release files for xlsx-evaluate 0.5.0

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

Source distribution (sdist)

Source distribution for xlsx-evaluate 0.5.0
File Size Uploaded
xlsx_evaluate-0.5.0.tar.gz 41.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xlsx-evaluate 0.5.0
File Interpreter ABI Platform
xlsx_evaluate-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 89.2 kB

Release files / xlsx_evaluate-0.5.0.tar.gz

Download URL xlsx_evaluate-0.5.0.tar.gz
Size 41.0 kB
Tags Source
SHA-256 checksum
How to use checksums
29a7cbd6e5bea0014678d7ec2e29581715fdb6ef7ecb9e27a4b8523da7abfdf1
BLAKE2b-256 checksum
How to use checksums
7cb0194fe96f3b962c335ef183548cd00e68c4827fc87bf93d67432aec389d4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.15 tqdm/4.65.0 importlib-metadata/6.3.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

Release files / xlsx_evaluate-0.5.0-py3-none-any.whl

Download URL xlsx_evaluate-0.5.0-py3-none-any.whl
Size 48.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a327f7ac653f2436e2eb4119aaf9fe8dc75a3820ffa458d67314715a0acb0b83
BLAKE2b-256 checksum
How to use checksums
fea0b6f384a5e0cc3f43f0439c7bc46535d9a11c0ba09b6a051f4e4b6d40f3ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.15 tqdm/4.65.0 importlib-metadata/6.3.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

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