xb.Expr#

class excelbird.Expr(expr_str: str | set, id: str | None = None, header: str | None = None, cell_style: excelbird._base.dotdict.Style | dict | None = None, header_style: excelbird._base.dotdict.Style | dict | None = None, table_style: excelbird._base.dotdict.Style | dict | bool | None = None, res_type: type | None = None, **kwargs)[source]#

Reference elements in parent container by name or index in a string expression. Immediately upon instantiating and Expr, all references enclosed in square brackets are parsed out and stored in a dictionary, where all values are None. The parent container of an Expr is responsible for resolving each of these keys by filling them with their corresponding element in the layout, and then evaluating.

Pass a string containing the code to be executed. It should look like normal python code, but instead of variable names, use square brackets and enclose the id or header of another layout element that may or may not exist yet. Quote marks are not necessary inside the brackets. For instance,

Expr("[some_cell_id] / ([some_column_header] + 2)", id="new_col")

Shorthand Syntax: If you don’t need to pass any keyword arguments, Expr can be more concisely written as a single-element set, containing the expression string:

{"[some_cell_id] / [other_cell_id]"}

This is useful when building a Func, where you might list many Expr together in succession.

Perhaps you only want to reference a single element, rather than execute an expression. In this case, the square brackets are not needed:

{"[some_cell_id]"}
# Can also be written as
{"some_cell_id"}

Again, this shorthand is most useful when building a Func

Parameters:
expr_strstr

The contents of the expression to be executed. It should look like normal python code, but instead of variables, use square brackets and enclose an id or header of another layout element.

idstr, optional

Id of the resulting element once the Expr is evaluated

headerstr, optional

Header of the resulting element once the Expr is evaluated. This will only have an effect if the resulting element can take a header

cell_styledict, optional

To be applied to the resulting element

header_styledict, optional

To be applied to the resulting element

table_styledict, optional

To be applied to the resulting element

**kwargsAny

Any other keyword arguments will be set as attributes on the resulting element

Methods

set