feat: enhance report on-screen, PDF print layout, and Excel exports with executive styling and audit sign-off
This commit is contained in:
@@ -99,7 +99,7 @@ def build_xlsx(report_payload: dict[str, Any]) -> BytesIO:
|
||||
summary_text = _format_summary_echo(report_payload.get("summary", {}))
|
||||
|
||||
# Row 1: Hospital Title
|
||||
ws.row_dimensions[1].height = 26
|
||||
ws.row_dimensions[1].height = 28
|
||||
c1 = ws.cell(row=1, column=1, value=title_text)
|
||||
c1.font = _TITLE_FONT
|
||||
c1.alignment = Alignment(vertical="center")
|
||||
@@ -111,10 +111,17 @@ def build_xlsx(report_payload: dict[str, Any]) -> BytesIO:
|
||||
c2.alignment = Alignment(vertical="center")
|
||||
|
||||
# Row 3: Summary KPIs strip
|
||||
ws.row_dimensions[3].height = 22
|
||||
ws.row_dimensions[3].height = 24
|
||||
c3 = ws.cell(row=3, column=1, value=summary_text)
|
||||
c3.font = _SUMMARY_FONT
|
||||
c3.alignment = Alignment(vertical="center")
|
||||
c3.fill = _SUMMARY_FILL
|
||||
c3.border = Border(
|
||||
top=Side(style="thin", color="BFDBFE"),
|
||||
bottom=Side(style="thin", color="BFDBFE"),
|
||||
left=Side(style="thin", color="BFDBFE"),
|
||||
right=Side(style="thin", color="BFDBFE"),
|
||||
)
|
||||
c3.alignment = Alignment(vertical="center", indent=1)
|
||||
|
||||
# Row 4: Spacer
|
||||
ws.row_dimensions[4].height = 10
|
||||
@@ -122,8 +129,20 @@ def build_xlsx(report_payload: dict[str, Any]) -> BytesIO:
|
||||
columns: list[dict[str, str]] = report_payload.get("columns", [])
|
||||
rows: list[dict[str, Any]] = report_payload.get("rows", [])
|
||||
|
||||
# Span summary strip styling across header columns
|
||||
if columns and len(columns) > 1:
|
||||
for c_idx in range(2, len(columns) + 1):
|
||||
sc = ws.cell(row=3, column=c_idx)
|
||||
sc.fill = _SUMMARY_FILL
|
||||
sc.border = Border(
|
||||
top=Side(style="thin", color="BFDBFE"),
|
||||
bottom=Side(style="thin", color="BFDBFE"),
|
||||
left=Side(style="thin", color="BFDBFE"),
|
||||
right=Side(style="thin", color="BFDBFE"),
|
||||
)
|
||||
|
||||
header_row = 5
|
||||
ws.row_dimensions[header_row].height = 26
|
||||
ws.row_dimensions[header_row].height = 28
|
||||
col_widths: list[int] = []
|
||||
|
||||
for c_idx, col in enumerate(columns, start=1):
|
||||
@@ -187,6 +206,22 @@ def build_xlsx(report_payload: dict[str, Any]) -> BytesIO:
|
||||
for c_idx, width in enumerate(col_widths, start=1):
|
||||
ws.column_dimensions[get_column_letter(c_idx)].width = min(50, max(14, width + 4))
|
||||
|
||||
# Pre-configure page setup for professional A4 Landscape printing / PDF conversion from Excel
|
||||
try:
|
||||
ws.page_setup.orientation = ws.ORIENTATION_LANDSCAPE
|
||||
ws.page_setup.paperSize = ws.PAPERSIZE_A4
|
||||
ws.page_setup.fitToPage = True
|
||||
ws.page_setup.fitToWidth = 1
|
||||
ws.page_setup.fitToHeight = 0
|
||||
ws.sheet_properties.pageSetUpPr.fitToPage = True
|
||||
ws.print_title_rows = f"{header_row}:{header_row}"
|
||||
ws.oddHeader.left.text = "&BPoona Hospital & Research Centre&B"
|
||||
ws.oddHeader.right.text = report_payload.get("title", "Operational Report")
|
||||
ws.oddFooter.left.text = "Confidential • Biomedical Asset Management System"
|
||||
ws.oddFooter.right.text = "Page &P of &N"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
buf = BytesIO()
|
||||
wb.save(buf)
|
||||
buf.seek(0)
|
||||
|
||||
Reference in New Issue
Block a user