1. What is formulas?

formulas implements an interpreter for Excel formulas, which parses and compile Excel formulas expressions.

Moreover, it compiles Excel workbooks to python and executes without using the Excel COM server. Hence, Excel is not needed.

2. Installation

To install it use (with root privileges):

$ pip install formulas

Or download the last git version and use (with root privileges):

$ python setup.py install

2.1. Install extras

Some additional functionality is enabled installing the following extras:

  • excel: enables to compile Excel workbooks to python and execute using: ExcelModel.
  • plot: enables to plot the formula ast and the Excel model.

To install formulas and all extras, do:

$ pip install formulas[all]

3. Basic Examples

The following sections will show how to:

  • parse a Excel formulas;
  • load, compile, and execute a Excel workbook;
  • extract a sub-model from a Excel workbook;
  • add a custom function.

3.1. Parsing formula

An example how to parse and execute an Excel formula is the following:

>>> import formulas
>>> func = formulas.Parser().ast('=(1 + 1) + B3 / A2')[1].compile()

To visualize formula model and get the input order you can do the following:

>>> list(func.inputs)
['A2', 'B3']
>>> func.plot(view=False)  # Set view=True to plot in the default browser.
SiteMap([(=((1 + 1) + (B3 / A2)), SiteMap())])

digraph dmap { graph [ratio=1] node [style=filled] label = <dmap> splines = ortho style = filled 18 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">((1 + 1) + (B3 / A2))</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-445ca173805a260dda86b21ea2618361bcf11e6b/bypass.html">bypass</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"((1 + 1) + (B3 / A2))\""] 19 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">(1 + 1)</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">Array(2.0, dtype=object)</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"(1 + 1)\""] 20 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">(B3 / A2)</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"(B3 / A2)\""] 21 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-445ca173805a260dda86b21ea2618361bcf11e6b/lambda.html">+&lt;0&gt;</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"+<0>\""] 22 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-445ca173805a260dda86b21ea2618361bcf11e6b/lambda-0.html">/</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"/\""] 23 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">A2</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"A2\""] 24 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">B3</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"B3\""] 25 [label=end fillcolor=blue shape=egg] 26 [label=start fillcolor=red shape=egg] 21 -> 18 19 -> 21 20 -> 21 22 -> 20 23 -> 22 24 -> 22 26 -> 23 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; A2</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] 26 -> 24 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; B3</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">1</TD></TR></TABLE>>] 18 -> 25 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">((1 + 1) + (B3 / A2)) --&gt; end</TD></TR><TR><TD align="RIGHT" border="1">out_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] }

Finally to execute the formula and plot the workflow:

>>> func(1, 5)
Array(7.0, dtype=object)
>>> func.plot(workflow=True, view=False)  # Set view=True to plot in the default browser.
SiteMap([(=((1 + 1) + (B3 / A2)), SiteMap())])

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 71 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/((1__1)__(B3__A2))-output.html">((1 + 1) + (B3 / A2))</TD></TR><TR><TD align="RIGHT" border="1">input_filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/((1__1)__(B3__A2))-input_filter_0.html">((1 + 1) + (B3 / A2))-input_filter 0</TD></TR><TR><TD align="RIGHT" border="1">output_filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/((1__1)__(B3__A2))-output_filter_0.html">((1 + 1) + (B3 / A2))-output_filter 0</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">4.0</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"((1 + 1) + (B3 / A2))\""] 72 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/(1__1)-output.html">(1 + 1)</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">Array(2.0, dtype=object)</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"(1 + 1)\""] 73 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/(B3__A2)-output.html">(B3 / A2)</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">2.0</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"(B3 / A2)\""] 74 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/lambda.html">+&lt;0&gt;</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">3.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2019-08-31T17:14:03.539681</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000370</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"+<0>\""] 75 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/lambda-0.html">/</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">1.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2019-08-31T17:14:03.539419</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000175</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"/\""] 76 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/A2-output.html">A2</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"A2\""] 77 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-866aac85cf35af27e97f5873e93cfcd472f142cc/B3-output.html">B3</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"B3\""] 78 [label=start fillcolor=red shape=egg] 78 -> 72 78 -> 76 78 -> 77 72 -> 74 76 -> 75 77 -> 75 74 -> 71 75 -> 73 73 -> 74 }

3.2. Excel workbook

An example how to load, calculate, and write an Excel workbook is the following:

>>> import formulas
>>> fpath, dir_output = 'excel.xlsx', 'output'  
>>> xl_model = formulas.ExcelModel().loads(fpath).finish()
>>> xl_model.calculate()
Solution(...)
>>> xl_model.write(dirpath=dir_output)
{'EXCEL.XLSX': {Book: <openpyxl.workbook.workbook.Workbook ...>}}

Tip

If you have or could have circular references, add circular=True to finish method.

To plot the dependency graph that depict relationships between Excel cells:

>>> dsp = xl_model.dsp
>>> dsp.plot(view=False)  # Set view=True to plot in the default browser.
SiteMap([(ExcelModel, SiteMap())])

digraph dmap { node [style=filled] label = <dmap> splines = ortho style = filled 129 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!A1</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">inputs</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!A1\""] 130 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!A2</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">2</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-0.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!A2\""] 131 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!A3</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">6</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-1.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!A3\""] 132 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!A3:A4</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-2.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!A3:A4\""] 133 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!A4</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">5</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-3.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!A4\""] 134 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!B1</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">Intermediate</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-4.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!B1\""] 135 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!B2</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-5.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!B2\""] 136 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!B3</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-6.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!B3\""] 137 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!B4</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-7.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!B4\""] 138 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C1</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">outputs</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-8.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!C1\""] 139 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C2</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-9.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!C2\""] 140 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C3</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-10.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!C3\""] 141 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C4</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/format_output-11.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!C4\""] 142 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/EXCEL.XLSXDATAA3A4.html">=&#x27;[EXCEL.XLSX]DATA&#x27;!A3:A4</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"='[EXCEL.XLSX]DATA'!A3:A4\""] 143 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/(EXCEL.XLSXDATAA2__EXCEL.XLSXDATAA3).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!A2 + &#x27;[EXCEL.XLSX]DATA&#x27;!A3)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!A2 + '[EXCEL.XLSX]DATA'!A3)\""] 144 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/(EXCEL.XLSXDATAB2_-_EXCEL.XLSXDATAA3).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!B2 - &#x27;[EXCEL.XLSX]DATA&#x27;!A3)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!B2 - '[EXCEL.XLSX]DATA'!A3)\""] 145 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/(EXCEL.XLSXDATAB2__EXCEL.XLSXDATAB3).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!B2 / &#x27;[EXCEL.XLSX]DATA&#x27;!B3)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!B2 / '[EXCEL.XLSX]DATA'!B3)\""] 146 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/(EXCEL.XLSXDATAB3__EXCEL.XLSXDATAC2).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!B3 ^ &#x27;[EXCEL.XLSX]DATA&#x27;!C2)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!B3 ^ '[EXCEL.XLSX]DATA'!C2)\""] 147 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/(EXCEL.XLSXDATAC2__EXCEL.XLSXDATAA2).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!C2 * &#x27;[EXCEL.XLSX]DATA&#x27;!A2)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!C2 * '[EXCEL.XLSX]DATA'!A2)\""] 148 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1e7a39569993e15b62fe4e88d7e268b36d0320ce/MAX(EXCEL.XLSXDATAA3A4_EXCEL.XLSXDATAB2).html">=MAX(&#x27;[EXCEL.XLSX]DATA&#x27;!A3:A4, &#x27;[EXCEL.XLSX]DATA&#x27;!B2)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=MAX('[EXCEL.XLSX]DATA'!A3:A4, '[EXCEL.XLSX]DATA'!B2)\""] 130 -> 143 130 -> 147 135 -> 145 135 -> 144 135 -> 148 131 -> 143 131 -> 144 131 -> 142 143 -> 135 139 -> 147 139 -> 146 136 -> 145 136 -> 146 145 -> 139 144 -> 136 147 -> 140 133 -> 142 132 -> 148 148 -> 137 146 -> 141 142 -> 132 }

To overwrite the default inputs that are defined by the excel file or to impose some value to a specific cell:

>>> xl_model.calculate(
...     inputs={
...         "'[EXCEL.XLSX]DATA'!A2": 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.
... )
Solution([("'[EXCEL.XLSX]DATA'!A2", <Ranges>('[EXCEL.XLSX]DATA'!A2)=[[3]]),
          ("'[EXCEL.XLSX]DATA'!A3", <Ranges>('[EXCEL.XLSX]DATA'!A3)=[[6]]),
          ("'[EXCEL.XLSX]DATA'!B3", <Ranges>('[EXCEL.XLSX]DATA'!B3)=[[1]]),
          ("'[EXCEL.XLSX]DATA'!B2", <Ranges>('[EXCEL.XLSX]DATA'!B2)=[[9.0]]),
          ("'[EXCEL.XLSX]DATA'!C2", <Ranges>('[EXCEL.XLSX]DATA'!C2)=[[9.0]]),
          ("'[EXCEL.XLSX]DATA'!C4", <Ranges>('[EXCEL.XLSX]DATA'!C4)=[[1.0]])])

To build a single function out of an excel model with fixed inputs and outputs, you can use the compile method of the ExcelModel that returns a DispatchPipe. This is a function where the inputs and outputs are defined by the data node ids (i.e., cell references).

>>> func = xl_model.compile(
...     inputs=[
...         "'[EXCEL.XLSX]DATA'!A2",  # First argument of the function.
...         "'[EXCEL.XLSX]DATA'!B3"   # Second argument of the function.
...     ], # To define function inputs.
...     outputs=[
...         "'[EXCEL.XLSX]DATA'!C2", "'[EXCEL.XLSX]DATA'!C4"
...     ] # To define function outputs.
... )
>>> func
<schedula.utils.dsp.DispatchPipe object at ...>
>>> [v.value[0, 0] for v in func(3, 1)]  # To retrieve the data.
[9.0, 1.0]
>>> func.plot(view=False)  # Set view=True to plot in the default browser.
SiteMap([(ExcelModel, SiteMap())])

digraph dmap { node [style=filled] label = <dmap> splines = ortho style = filled 235 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!A2</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/format_output.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!A2\""] 236 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!A3</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">6</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/format_output-0.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!A3\""] 237 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!B2</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/format_output-1.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!B2\""] 238 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!B3</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/format_output-2.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!B3\""] 239 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C2</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/format_output-3.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!C2\""] 240 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C4</TD></TR><TR><TD align="RIGHT" border="1">filter 0</TD><TD align="LEFT" border="1" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/format_output-4.html">format_output</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip="\"'[EXCEL.XLSX]DATA'!C4\""] 241 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/(EXCEL.XLSXDATAA2__EXCEL.XLSXDATAA3).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!A2 + &#x27;[EXCEL.XLSX]DATA&#x27;!A3)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!A2 + '[EXCEL.XLSX]DATA'!A3)\""] 242 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/(EXCEL.XLSXDATAB2__EXCEL.XLSXDATAB3).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!B2 / &#x27;[EXCEL.XLSX]DATA&#x27;!B3)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!B2 / '[EXCEL.XLSX]DATA'!B3)\""] 243 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-72dffdc1038a02a1e11afcc7e747361c034602a9/(EXCEL.XLSXDATAB3__EXCEL.XLSXDATAC2).html">=(&#x27;[EXCEL.XLSX]DATA&#x27;!B3 ^ &#x27;[EXCEL.XLSX]DATA&#x27;!C2)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="\"=('[EXCEL.XLSX]DATA'!B3 ^ '[EXCEL.XLSX]DATA'!C2)\""] 244 [label=end fillcolor=blue shape=egg] 245 [label=start fillcolor=red shape=egg] 239 -> 243 242 -> 239 243 -> 240 237 -> 242 238 -> 242 238 -> 243 241 -> 237 235 -> 241 236 -> 241 245 -> 235 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; &#x27;[EXCEL.XLSX]DATA&#x27;!A2</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] 245 -> 238 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; &#x27;[EXCEL.XLSX]DATA&#x27;!B3</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">1</TD></TR></TABLE>>] 239 -> 244 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C2 --&gt; end</TD></TR><TR><TD align="RIGHT" border="1">out_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] 240 -> 244 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">&#x27;[EXCEL.XLSX]DATA&#x27;!C4 --&gt; end</TD></TR><TR><TD align="RIGHT" border="1">out_id</TD><TD align="LEFT" border="1">1</TD></TR></TABLE>>] }

3.3. Custom functions

An example how to add a custom function to the formula parser is the following:

>>> import formulas
>>> FUNCTIONS = formulas.get_functions()
>>> FUNCTIONS['MYFUNC'] = lambda x, y: 1 + y + x
>>> func = formulas.Parser().ast('=MYFUNC(1, 2)')[1].compile()
>>> func()
4

4. Next moves

Things yet to do: implement the missing Excel formulas.