Skip to content
Snippets Groups Projects
Verified Commit 9324ba7a authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP: Filling XLSX

parent 2dc4f469
No related branches found
No related tags found
2 merge requests!100WIP: Filling XLSX: Seems to be working.,!93Filling XLSX: Everything except multiple choice.
Pipeline #48178 passed
......@@ -57,11 +57,12 @@ def _get_path_rows(worksheet):
return rows
def _generate_path_col_mapping(workbook):
rt_col = _get_row_type_column_index(workbook)
def _next_row_index(sheet) -> int:
"""Return the index for the next data row.
for col in workbook.columns:
pass
This is defined as the first row without any content.
"""
return sheet.max_row
class TemplateFiller:
......@@ -117,10 +118,15 @@ class TemplateFiller:
assert len(common_path) >= 1
self._sheet_index[".".join(common_path)] = SimpleNamespace(
common_path=common_path, sheetname=sheetname, sheet=sheet)
common_path=common_path, sheetname=sheetname, sheet=sheet, col_index=col_index)
def _handle_data(self, data: dict, current_path: List[str] = None):
"""Handle the data and write it into ``workbook``.
Parameters
----------
data: dict
The data at the current path position. Elements may be dicts, lists or simple scalar values.
"""
if current_path is None:
current_path = []
......@@ -129,24 +135,31 @@ class TemplateFiller:
if isinstance(content, list):
if not content:
continue
# Must be all of the same type.
assert len(set(type(entry) for entry in content)) == 1
if isinstance(content[0], dict):
# An array of objects: must go into exploded sheet
for entry in content:
self._handle_data(data=entry, current_path=path)
continue
for entry in content:
pass
else:
self._handle_single_data(data=content, current_path=path)
self._handle_simple_data(data=content, current_path=path)
def _handle_single_data(self, data, current_path: List[str]):
def _handle_simple_data(self, data, current_path: List[str]):
"""Enter this single data item into the workbook.
Parameters
----------
data: dict
The data at the current path position. Must be single items (dict or simple scalar) or lists of
simple values.
"""
sheet = self._sheet_index[".".join(current_path)].sheet
next_row = _next_row_index(sheet)
for name, content in data.items():
if isinstance(content, list):
# TODO handle later
# scalar elements: semicolon separated
# nested dicts: recurse
continue
if isinstance(content, dict):
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment