notebook
This commit is contained in:
18
60 DXA.py
18
60 DXA.py
@@ -97,6 +97,16 @@ def find_dxa_file(rod_cis: str) -> str:
|
||||
|
||||
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 ==================
|
||||
with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer:
|
||||
df.to_excel(writer, index=False, sheet_name="DXA")
|
||||
@@ -110,10 +120,16 @@ with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer:
|
||||
cell.alignment = Alignment(horizontal="center", vertical="center")
|
||||
cell.fill = header_fill
|
||||
|
||||
# Auto column width
|
||||
# Auto column width, but hardcode FILE column to 120
|
||||
from openpyxl.utils import get_column_letter
|
||||
|
||||
for col in ws.columns:
|
||||
col_letter = get_column_letter(col[0].column)
|
||||
header = ws.cell(row=1, column=col[0].column).value
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user