caosadvancedtools.table_json_conversion.fill_xlsx module#
Class and function to fill an XLSX template from actual data.
- class caosadvancedtools.table_json_conversion.fill_xlsx.TemplateFiller(workbook: Workbook, graceful: bool = False)#
Bases:
objectClass to fill XLSX templates. Has an index for all relevant columns.
- class Context(current_path: list[str] | None = None, props: dict[str, Any] | None = None)#
Bases:
objectContext for an entry: simple properties of all ancestors, organized in a dict.
This is similar to a dictionary with all scalar element properties at the tree nodes up to the root. Siblings in lists and dicts are ignored. Additionally the context knows where its current position is.
Lookup of elements can easily be achieved by giving the path (as
list[str]or stringified path).- fill_from_data(data: dict[str, Any])#
Fill current level with all scalar elements of
data.
- fill_data(data: dict)#
Fill the data into the workbook.
- property workbook#
Return the workbook of this TemplateFiller.
- caosadvancedtools.table_json_conversion.fill_xlsx.fill_template(data: dict | str | TextIO, template: str, result: str | Path, validation_schema: dict | str | TextIO | None = None) None#
Insert json data into an xlsx file, according to a template.
This function fills the json data into the template stored at
templateand stores the result asresult.- Parameters:
data (Union[dict, str, TextIO]) – The data, given as Python dict, path to a file or a file-like object.
template (str) – Path to the XLSX template.
result (str) – Path for the result XLSX.
validation_schema (dict, optional) – If given, validate the date against this schema first. This raises an exception if the validation fails. If no validation schema is given, try to ignore more errors in the data when filling the XLSX template.
development (Possible future)
---------------------------
option (- Add an allow_missing_foreign)
props.get(key). (which would replace props[key] by)