Skip to content

Explicite default column width #131

Description

@buhtz

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
image

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"):
image

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:
image

Even you format that table as a "table with header" in Excel the auto-fit function create this
image

#!/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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions