From 2686a10c0c1c752b108bd5d0d445a3e86ef6a70f Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Tue, 5 Mar 2024 16:55:48 +0100
Subject: [PATCH] ENH: Highlighting of reference columns.

---
 .../table_json_conversion/table_generator.py          | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/caosadvancedtools/table_json_conversion/table_generator.py b/src/caosadvancedtools/table_json_conversion/table_generator.py
index 5b9c6577..07fac819 100644
--- a/src/caosadvancedtools/table_json_conversion/table_generator.py
+++ b/src/caosadvancedtools/table_json_conversion/table_generator.py
@@ -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]))
-- 
GitLab