Tw22
This commit is contained in:
77
54 Dekurz export noRTF.py
Normal file
77
54 Dekurz export noRTF.py
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Test export of DEKURS table without RTF column, to verify Excel corruption source.
|
||||
"""
|
||||
|
||||
import time
|
||||
import fdb
|
||||
import pandas as pd
|
||||
from pathlib import Path
|
||||
from openpyxl.styles import Font, Alignment, PatternFill
|
||||
from openpyxl.utils import get_column_letter
|
||||
|
||||
# ================== CONFIGURATION ==================
|
||||
FDB_PATH = r"z:\Medicus 3\data\medicus.fdb"
|
||||
EXPORT_DIR = Path(r"D:\Dropbox\!!!Days\Downloads Z230")
|
||||
timestamp = time.strftime("%Y-%m-%d %H-%M-%S")
|
||||
xlsx_path = EXPORT_DIR / f"Dekurz export noRTF {timestamp}.xlsx"
|
||||
|
||||
DATE_FROM = "2024-01-01"
|
||||
|
||||
# ================== FIREBIRD CONNECTION ==================
|
||||
con = fdb.connect(
|
||||
dsn=f"localhost:{FDB_PATH}",
|
||||
user="sysdba",
|
||||
password="masterkey",
|
||||
charset="WIN1250"
|
||||
)
|
||||
|
||||
# ================== QUERY (without "DEKURS" column) ==================
|
||||
sql = f"""
|
||||
SELECT
|
||||
dekurs.id,
|
||||
kar.prijmeni,
|
||||
kar.jmeno,
|
||||
kar.rodcis,
|
||||
uzivatel.zkratka,
|
||||
dekurs.datum
|
||||
FROM dekurs
|
||||
JOIN kar ON dekurs.idpac = kar.idpac
|
||||
JOIN uzivatel ON dekurs.iduzi = uzivatel.iduzi
|
||||
WHERE dekurs.datum >= DATE '{DATE_FROM}'
|
||||
ORDER BY dekurs.datum DESC
|
||||
"""
|
||||
|
||||
df = pd.read_sql(sql, con)
|
||||
con.close()
|
||||
|
||||
# Rename for nicer Excel output
|
||||
df.rename(columns={
|
||||
"ID": "ID záznamu",
|
||||
"PRIJMENI": "Příjmení",
|
||||
"JMENO": "Jméno",
|
||||
"RODCIS": "Rodné číslo",
|
||||
"ZKRATKA": "Lékař",
|
||||
"DATUM": "Datum"
|
||||
}, inplace=True)
|
||||
|
||||
# ================== EXPORT TO EXCEL ==================
|
||||
with pd.ExcelWriter(xlsx_path, engine="openpyxl") as writer:
|
||||
df.to_excel(writer, index=False, sheet_name="Dekurz")
|
||||
ws = writer.sheets["Dekurz"]
|
||||
|
||||
# Header styling
|
||||
header_fill = PatternFill(start_color="FFD966", end_color="FFD966", fill_type="solid")
|
||||
for cell in ws[1]:
|
||||
cell.font = Font(bold=True)
|
||||
cell.alignment = Alignment(horizontal="center", vertical="center")
|
||||
cell.fill = header_fill
|
||||
|
||||
# Auto column widths
|
||||
for col in ws.columns:
|
||||
max_len = max(len(str(cell.value)) if cell.value else 0 for cell in col)
|
||||
ws.column_dimensions[get_column_letter(col[0].column)].width = min(max_len + 2, 60)
|
||||
|
||||
print(f"✅ Hotovo: {xlsx_path}")
|
||||
Reference in New Issue
Block a user