Commit f7ee74aa authored by Nic's avatar Nic
Browse files

fix XLSX template dumping

parent ac120ce0
......@@ -311,16 +311,23 @@ def fmt_dict(attributes=()):
return fmt
def dump_xlsx_template(schemas, output, tabs=None, excluded_tabs=None):
def dump_xlsx_template(schemas, output, tabs=(), excluded_tabs=None):
"""creates a blank XSLX spreadsheet based on provided schema"""
# -------------------------------------------------------------------------
alphabet = string.ascii_uppercase # "ABC..."
# -------------------------------------------------------------------------
# read shema(s)
data = IVData()
data.read_schema(*schemas)
# -------------------------------------------------------------------------
# eventually filter with tabs wishlist
schemas = data._schemas.copy()
if tabs:
schemas = {k: v for k, v in schemas.items() if k in tabs}
if excluded_tabs:
schemas = {k: v for k, v in schemas.items() if k not in excluded_tabs}
# -------------------------------------------------------------------------
# check implicit tabs xcalls
tabs = list(tabs)
for tabname, schema in data._schemas.items():
for tabname, schema in schemas.items():
for referencing_col, (
referenced_tab,
referenced_col,
......@@ -328,19 +335,9 @@ def dump_xlsx_template(schemas, output, tabs=None, excluded_tabs=None):
if referenced_tab not in tabs:
logging.warning(f"add referenced {referenced_tab}")
tabs.append(referenced_tab)
# -------------------------------------------------------------------------
# eventually filter with tabs wishlist
if tabs:
data._schemas = {k: v for k, v in data._schemas.items() if k in tabs}
if excluded_tabs:
data._schemas = {
k: v for k, v in data._schemas.items() if k not in excluded_tabs
}
# -------------------------------------------------------------------------
# automatically integrate referenced tabs
# -------------------------------------------------------------------------
# get columns and attributes
cols = data.dump_template()
data._schemas = schemas
cols = data.dump_template() # get columns and attributes
cols = {k: cols[k] for k in tabs} # reorder as required by `tabs` order
with pd.ExcelWriter(output) as writer:
workbook = writer.book
# prepare formats
......@@ -379,7 +376,7 @@ def dump_xlsx_template(schemas, output, tabs=None, excluded_tabs=None):
else:
fmt = default_format
worksheet.write_string(0, i, colname, cell_format=fmt)
cell_header = "{col}{row}".format(col=alphabet[i], row=1)
cell_header = "{col}{row}".format(col=string.ascii_uppercase[i], row=1)
# -------------------------------------------------------------
# process comments
types = set((colspecs[colname]["items"].get("type"),))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment