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

ENH: Highlighting of reference columns.

parent 79500a20
No related branches found
No related tags found
3 merge requests!100WIP: Filling XLSX: Seems to be working.,!94ENH: add framework for converting json schema into table templates,!93Filling XLSX: Everything except multiple choice.
Pipeline #48141 passed
......@@ -28,6 +28,7 @@ from enum import Enum
from typing import Dict, List, Optional, Tuple
from openpyxl import Workbook
from openpyxl.styles import PatternFill
from openpyxl.workbook.child import INVALID_TITLE_REGEX
......@@ -306,7 +307,11 @@ class XLSXTemplateGenerator(TableTemplateGenerator):
self, sheets: Dict[str, Dict[str, Tuple[ColumnType, Optional[str], list]]]):
"""Create and return a nice workbook for the given sheets."""
wb = Workbook()
yellowfill = PatternFill(fill_type="solid", fgColor='00FFFFAA')
assert wb.sheetnames == ["Sheet"]
# remove initial sheet
del wb['Sheet']
for sheetname, sheetdef in sheets.items():
ws = wb.create_sheet(re.sub(INVALID_TITLE_REGEX, '_', sheetname))
# First row will by the COL_TYPE row.
......@@ -332,6 +337,9 @@ class XLSXTemplateGenerator(TableTemplateGenerator):
for path_index, el in enumerate(path):
ws.cell(2 + path_index, 2 + index, el)
ws.cell(header_index, 2 + index, colname)
if ct == ColumnType.FOREIGN:
# Visual highlighting
ws.cell(header_index, 2 + index).fill = yellowfill
if desc:
ws.cell(description_index, 2 + index, desc)
......@@ -343,9 +351,6 @@ class XLSXTemplateGenerator(TableTemplateGenerator):
# hide special column
ws.column_dimensions['A'].hidden = True
# remove initial sheet
del wb['Sheet']
# order sheets
# for index, sheetname in enumerate(sorted(wb.sheetnames)):
# wb.move_sheet(sheetname, index-wb.index(wb[sheetname]))
......
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