-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Different from pandas.to_excel()
it seems to me that StyelFrame.to_excel()
does explicit set the width of each column based on its values. I am not sure here it is just a hypothesis.
Please see the full code at the end of that report.
The excel result looks like this
I assume that column "B" was set to a default minimum with because there is much space before and after the values.
I also assume that column "C" was set to the with of its longest value (33123
).
I assume that the with of headers are ignored.
Now I do a "auto fit column width" in Excel (in German "Spaltenbreite automatisch anpassen"):
The index column A
is the only that was fit to the with of its values/contents.
Column B
and C
does not change. That is why I assume there an explicit width.
The default Excel behavior would be to set the width that it fit to the content/values of a column:
Even you format that table as a "table with header" in Excel the auto-fit function create this
#!/usr/bin/env python3
import os
import sys
import pathlib
import pandas
import styleframe
import styleframe.utils
print(styleframe._versions_)
df = pandas.DataFrame(
data={
'idx1': list('AABB'),
'column with long caption': [1234, 345, 33123, 2],
}
)
print(df)
file_path = pathlib.Path.cwd() / 'test.xlsx'
default_style = styleframe.Styler(font_size=14)
sf = styleframe.StyleFrame(df, styler_obj=default_style)
sf.to_excel(file_path, index=True).save()
os.system(str(file_path))
Changing this would break the default behaviour of your users. I am aware of this.
But maybe there could be switch or something to avoid the setting of an explicit width.
IMHO better default behaviour would be to auto-fit the width.