vinci1it2000 / formulas

Excel formulas interpreter in Python.
https://formulas.readthedocs.io/
European Union Public License 1.1
342 stars 75 forks source link

General info #120

Closed ShieldTrade closed 8 months ago

ShieldTrade commented 11 months ago

Hi,

Where can I find Excel formulas already implemented?

Is it possible to calculate a single cell or a range?

Thankyou

vinci1it2000 commented 8 months ago
  1. You can install it using the command pip install formulas or if you have conda installed, conda install -c conda-forge formulas.
  2. You can load a partial Excel model from the output cells or ranges; you can use the from_ranges method of the ExcelModel:
>>> xl = formulas.ExcelModel().from_ranges(
...     "'[excel.xlsx]DATA'!C2:D2" % fpath,  # Output range.
...     "'[excel.xlsx]DATA'!B4" % fpath,  # Output cell.
... )

If you want to load the Excel once and use it interactively, you can specify the outputs when calculating so it will calculate only the needed results.

>>> xl_model.calculate(
...     inputs={
...         "'[excel.xlsx]'!INPUT_A": 3,  # To overwrite the default value.
...         "'[excel.xlsx]DATA'!B3": 1  # To impose a value to B3 cell.
...     },
...     outputs=[
...        "'[excel.xlsx]DATA'!C2", "'[excel.xlsx]DATA'!C4"
...     ] # To define the outputs that you want to calculate.
... )