git
This commit is contained in:
@@ -61,17 +61,28 @@ def get_data():
|
||||
# ==============================
|
||||
|
||||
def auto_adjust_columns(writer, df, sheet_name):
|
||||
"""Pomocná funkce pro automatické rozšíření sloupců v Excelu"""
|
||||
"""Bezpečné automatické nastavení šířky sloupců"""
|
||||
worksheet = writer.sheets[sheet_name]
|
||||
|
||||
for idx, col in enumerate(df.columns):
|
||||
max_len = max(
|
||||
df[col].astype(str).map(len).max(),
|
||||
len(str(col))
|
||||
) + 2
|
||||
if max_len > 60: max_len = 60
|
||||
series = df[col]
|
||||
|
||||
max_len = len(str(col)) # minimálně délka hlavičky
|
||||
|
||||
for val in series:
|
||||
if val is None or (isinstance(val, float) and pd.isna(val)):
|
||||
length = 0
|
||||
else:
|
||||
length = len(str(val))
|
||||
|
||||
if length > max_len:
|
||||
max_len = length
|
||||
|
||||
max_len = min(max_len + 2, 60)
|
||||
worksheet.set_column(idx, idx, max_len)
|
||||
|
||||
|
||||
|
||||
# ==============================
|
||||
# 🚀 HLAVNÍ LOGIKA
|
||||
# ==============================
|
||||
|
||||
Reference in New Issue
Block a user