feat: enhance Excel table header and register styling with Navy fill, white bold font, borders, and AutoFilter
This commit is contained in:
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import openpyxl
|
||||
from openpyxl.styles import Font, PatternFill
|
||||
from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
|
||||
from openpyxl.utils import get_column_letter
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -36,7 +36,13 @@ VALID_STATUSES = ("in_service", "under_repair", "out_of_service", "condemned")
|
||||
VALID_CRITICALITIES = ("critical", "non_critical")
|
||||
|
||||
_HEADER_FILL = PatternFill(start_color="1E3A8A", end_color="1E3A8A", fill_type="solid")
|
||||
_HEADER_FONT = Font(color="FFFFFF", bold=True)
|
||||
_HEADER_FONT = Font(name="Calibri", size=11, color="FFFFFF", bold=True)
|
||||
_HEADER_BORDER = Border(
|
||||
left=Side(style="thin", color="334155"),
|
||||
right=Side(style="thin", color="334155"),
|
||||
top=Side(style="thin", color="334155"),
|
||||
bottom=Side(style="medium", color="0F172A"),
|
||||
)
|
||||
|
||||
|
||||
def _auto_fit_columns(ws, max_width: int = 42) -> None:
|
||||
@@ -58,6 +64,11 @@ def build_import_template_xlsx(db: Session) -> BytesIO:
|
||||
cell = ws.cell(row=1, column=col_idx, value=col_name)
|
||||
cell.fill = _HEADER_FILL
|
||||
cell.font = _HEADER_FONT
|
||||
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
||||
cell.border = _HEADER_BORDER
|
||||
ws.row_dimensions[1].height = 26
|
||||
ws.views.sheetView[0].showGridLines = True
|
||||
ws.auto_filter.ref = f"A1:{get_column_letter(len(IMPORT_COLUMNS))}2"
|
||||
ws.freeze_panes = "A2"
|
||||
|
||||
departments = (
|
||||
@@ -119,6 +130,8 @@ def build_import_template_xlsx(db: Session) -> BytesIO:
|
||||
|
||||
# Sheet 2: Master Reference
|
||||
ref = wb.create_sheet(title="Master Reference")
|
||||
ref.row_dimensions[1].height = 26
|
||||
ref.views.sheetView[0].showGridLines = True
|
||||
headers_map = [
|
||||
(1, "Department Code"),
|
||||
(2, "Department Name"),
|
||||
@@ -133,6 +146,8 @@ def build_import_template_xlsx(db: Session) -> BytesIO:
|
||||
c = ref.cell(row=1, column=col_idx, value=label)
|
||||
c.fill = _HEADER_FILL
|
||||
c.font = _HEADER_FONT
|
||||
c.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
||||
c.border = _HEADER_BORDER
|
||||
ref.freeze_panes = "A2"
|
||||
|
||||
dept_by_id = {d.id: d for d in departments}
|
||||
|
||||
Reference in New Issue
Block a user