Skip to main content

Calculate XLSX formulas

Project description

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

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

xlsx_evaluate-0.4.6.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

xlsx_evaluate-0.4.6-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file xlsx_evaluate-0.4.6.tar.gz.

File metadata

  • Download URL: xlsx_evaluate-0.4.6.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.12.0 keyring/23.7.0 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.13

File hashes

Hashes for xlsx_evaluate-0.4.6.tar.gz
Algorithm Hash digest
SHA256 8e8bc507d43efdd87955da5bd09d31d4774448e63b1078f39b99407211dc967f
MD5 ab9194979928d02c66c4659d1d751a6d
BLAKE2b-256 13af37824f5478ac46d3df200afad4c8427286ea14e9f859c9acb3e627b1ceb1

See more details on using hashes here.

File details

Details for the file xlsx_evaluate-0.4.6-py3-none-any.whl.

File metadata

  • Download URL: xlsx_evaluate-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 48.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.12.0 keyring/23.7.0 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.13

File hashes

Hashes for xlsx_evaluate-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 33ecf0187cdcd2c658dbfd2a96658d6a6a3194ed2f96d26ede815d5a616616a6
MD5 805e96d41054339b6b2448268398ef7b
BLAKE2b-256 958661587d1e3bc9be2594d6c9b8aff5826c42c128e0dd088ea83f83d6203b87

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