xb.VFrame#
- class excelbird.VFrame(fn: str | excelbird.core.function.Func, **kwargs)[source]#
- class excelbird.VFrame(ex: str | set | excelbird.core.expression.Expr, **kwargs)
- class excelbird.VFrame(*args: Any, children: list | None = None, id: str | int | None = None, schema: None = None, sep: Any | None = None, sizes: list | None = None, border_top: bool | str | None = None, border_right: bool | str | None = None, border_bottom: bool | str | None = None, border_left: bool | str | None = None, border: Optional[Union[bool, str, Iterable]] = None, background_color: str | None = None, fill_empty: bool | 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, **kwargs)
A 2-dimensional vector that can be used in a python expression
Direction: vertical
Child Type:
Row
Note
Unlike
Frame, VFrame cannot be formatted as a table in Excel. Paramtable_stylewill be ignored.- Parameters:
- *args
Union[Col,Row,Frame,VFrame, list,tuple,pd.Series,pd.DataFrame,np.ndarray,Gap,Item,Expr,Func, set, None] Children must be (or resolve to) a series. Frame holds Cols, and VFrame holds Rows - Gap and Item will be interpreted as the respective element. Can also take any value that will be resolved to one of the above types, such as a list, tuple, pandas Series, etc. 2-dimensional arguments, such as pandas DataFrame, will be ‘exploded’ inplace into separate 1-dimensional elements.
- childrenlist,
optional Will be combined with args
- idstr,
optional Unique identifier to store globally so that this element can be referenced elsewhere in the layout without being assigned to a variable
- schema
Schema,optional A Schema object to use to rename child headers to desired output names at write time.
- sep
Gapor bool or int or dict,optional A sep in any excelbird layout element inserts a Gap between each of its children. If True, a default of
Gap(1)is used. If int,Gap(sep)will be used. If a dict,Gap(1, **sep)will be used.- sizesdict[str, int],
optional Specify the column width (or row height, if VFrame) for any child element by header. Keys should be the header of a child element, and values should be integers representing that element’s size. Note: unlike most excelbird styling, this argument will override any other column widths / row heights given to the children.
- background_colorstr,
optional Hex code for background color. Will be applied to fill_color of any Gap child who hasn’t specified its own fill_color. Will also be passed down to any Col/Row child who hasn’t specified its own background_color.
- fill_emptybool,
optional Fill shorter children (if children vary in length) with
Cell("")so that all lengths are matching, and all Cells inside the child will follow the same style. If False or None, these empty spaces will instead be filled withGap(), to which the child’s background_color will be applied, if present.- cell_styledict,
optional Will be applied to each child’s cell_style
- header_styledict,
optional Will be applied to each child’s header_style
- table_styledict or bool,
optional Format a Frame as an Excel table. (ignored for VFrame). If True, default style ‘name=”TableStyleMedium2”’ is used. If dict, key ‘displayName’ will be used as the table name, and all other key/values will be passed to openpyxl.worksheet.table.TableStyleInfo.
- borderlist[
tupleor str or bool]ortuple[str or bool, str or bool]orstr or bool,optional Syntax inspired by CSS. A non-list value will be applied to all 4 sides. If list, length can be 2, 3, or 4 elements. Order is [top, right, bottom, left]. If length 2, apply the first element to top and bottom border, and apply the second element to right and left. To apply border to children instead, use cell_style.
- border_top
tuple[str or bool, str or bool]orstr or bool,optional Top border. If True, a thin black border is used. If string (6 char hex code), use the default weight and apply the specified color. If string (valid weight name), use the default color and apply the specified weight. If tuple, apply the first element as weight, and second element as color.
- border_right
tuple[str or bool, str or bool]orstr or bool,optional Right border. See border_top
- border_bottom
tuple[str or bool, str or bool]orstr or bool,optional Bottom border. See border_top
- border_left
tuple[str or bool, str or bool]orstr or bool,optional Left border. See border_top
- **kwargs
Any Remaining kwargs will be applied to cell_style
- *args
- Attributes:
Methods
get(key[, default])Safely get an element.
range([include_headers])Get a reference to the entire range of the frame, instead of a vector of cell references.
ref([inherit_style])Get a new object with cell references to those in the caller.
set(**kwargs)Set attributes inline.
transpose(**kwargs)Convert to sibling type.
Properties
- excelbird.VFrame.headers#
The headers of each child. None will be placed at the index of children who have no header, so the returned list will be of the same length as self.
- Returns:
- list[str or None]
- excelbird.VFrame.loc#
When subscripted, provides an alternative to the default subscripting behavior. Instead of returning the elements found by the slice, a subscripted
locwill return a range from the found elements.Warning
Slices of
locwill be inclusive of the ‘stop’ argument, unlike normal slices which exclude it.For instance,
my_frame.loc[2:5]is equivalent tomy_frame[2] >> my_frame[5].- Returns:
Locable
xb.VFrame Methods#
- excelbird.VFrame.range(self, include_headers: bool = False)#
Get a reference to the entire range of the frame, instead of a vector of cell references.
- excelbird.VFrame.ref(self, inherit_style: bool = False, **kwargs) VFrame#
Get a new object with cell references to those in the caller. This assumes that both the calling object and the returned object will be placed in the workbook.
Note
Calling
.ref()is not necessary when an object is used in a python expression (i.e.some_cell + some_row) and should only be used to duplicate data across a workbook.- Parameters:
- inherit_stylebool,
defaultFalse Copy the caller’s style to the returned object.
- inherit_stylebool,
- Returns:
Self
Notes
Note
Children’s
headerattributes are stylistic attributes, and therefore will not be passed to the returned object’s children unlessinherit_style=True. And, if style is inherited, headers will be copied over to the children, instead of cell references to them.
- excelbird.VFrame.transpose(self, **kwargs) Frame#
Convert to sibling type. Places current children into the returned object, without copying or making cell references to them.
- Parameters:
- **kwargs
Any Keyword arguments to apply as attributes to the new object.
- **kwargs
- Returns:
Notes
Assumes that the caller won’t be placed in the layout. Do not place both the calling object and returned object in the layout, since they both contain the same children.
# 'current' must not be placed in the workbook. new = current.transpose()
To include both, use a reference of current instead
new = current.ref().transpose()
- excelbird.VFrame.get(self, key, default=None) Any#
Safely get an element.
- Parameters:
- keystr or int
The index,
idorheader(if series) of a child element.- default
Any,defaultNone Value to return if nothing is found
- Returns:
AnyNote that some dynamic elements, such as
GaporExprmay not have been resolved to a valid child type yet.
Notes
Note
Excelbird containers are all subclasses of
listso you can access elements using square brackets the same as you would with a list.
- excelbird.VFrame.set(self, **kwargs) ListIndexableById#
Set attributes inline.
Useful if defining a complex layout and setting attributes dynamically via either a list comprehension or inline conditionals.
- Parameters:
- **kwargs
Any All keyword arguments will be set as attributes on self, via
setattr()
- **kwargs
- Returns:
Self
Examples
Instead of having to set an attribute ahead of time, like
if len(elem) > 5: elem.bold = True Book( elem, )
Set the attribute inline!
Book( elem if len(elem) < 5 else elem.set(bold=True) )