notebook
This commit is contained in:
22
60 DXA.py
22
60 DXA.py
@@ -97,6 +97,16 @@ def find_dxa_file(rod_cis: str) -> str:
|
|||||||
|
|
||||||
df["FILE"] = df["RODCIS"].apply(find_dxa_file)
|
df["FILE"] = df["RODCIS"].apply(find_dxa_file)
|
||||||
|
|
||||||
|
|
||||||
|
# ================== CLEAN OLD REPORTS ==================
|
||||||
|
for f in EXPORT_DIR.glob("*_DXA_report.xlsx"):
|
||||||
|
try:
|
||||||
|
f.unlink()
|
||||||
|
print(f"🗑️ Deleted old report: {f.name}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Could not delete {f.name}: {e}")
|
||||||
|
|
||||||
|
|
||||||
# ================== EXPORT TO EXCEL ==================
|
# ================== EXPORT TO EXCEL ==================
|
||||||
with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer:
|
with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer:
|
||||||
df.to_excel(writer, index=False, sheet_name="DXA")
|
df.to_excel(writer, index=False, sheet_name="DXA")
|
||||||
@@ -110,12 +120,18 @@ with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer:
|
|||||||
cell.alignment = Alignment(horizontal="center", vertical="center")
|
cell.alignment = Alignment(horizontal="center", vertical="center")
|
||||||
cell.fill = header_fill
|
cell.fill = header_fill
|
||||||
|
|
||||||
# Auto column width
|
# Auto column width, but hardcode FILE column to 120
|
||||||
from openpyxl.utils import get_column_letter
|
from openpyxl.utils import get_column_letter
|
||||||
|
|
||||||
for col in ws.columns:
|
for col in ws.columns:
|
||||||
col_letter = get_column_letter(col[0].column)
|
col_letter = get_column_letter(col[0].column)
|
||||||
max_len = max(len(str(cell.value)) if cell.value else 0 for cell in col)
|
header = ws.cell(row=1, column=col[0].column).value
|
||||||
ws.column_dimensions[col_letter].width = min(max_len + 2, 80)
|
|
||||||
|
if header == "FILE":
|
||||||
|
ws.column_dimensions[col_letter].width = 120
|
||||||
|
else:
|
||||||
|
max_len = max(len(str(cell.value)) if cell.value else 0 for cell in col)
|
||||||
|
ws.column_dimensions[col_letter].width = min(max_len + 2, 80)
|
||||||
|
|
||||||
# Borders
|
# Borders
|
||||||
thin = Side(border_style="thin", color="000000")
|
thin = Side(border_style="thin", color="000000")
|
||||||
|
|||||||
Reference in New Issue
Block a user