-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explicite default column width #131
Comments
We do have
Consider this: from styleframe import StyleFrame
long_string = 'a' * 100
data_with_long_column_name = {long_string: ['a']}
data_with_long_content = {'a': [long_string]}
long_column_name_sf = StyleFrame(data_with_long_column_name)
long_content_sf = StyleFrame(data_with_long_content)
long_column_name_sf.to_excel('long_column_name_sf_without_best_fit.xlsx').save()
long_content_sf.to_excel('long_content_sf_without_best_fit.xlsx').save()
long_column_name_sf.to_excel('long_column_name_sf_with_best_fit.xlsx', best_fit=long_string).save()
long_content_sf.to_excel('long_content_sf_with_best_fit.xlsx', best_fit='a').save() long_column_name_sf_without_best_fit.xlsx: long_content_sf_without_best_fit.xlsx: long_column_name_sf_with_best_fit.xlsx: long_content_sf_with_best_fit.xlsx: The fix should be fairly easy, StyleFrame/styleframe/style_frame.py Line 536 in c8a1117
self.set_column_width_dict({column: (max(self.data_df[column].astype(str).str.len().max(), len(column)) + self.A_FACTOR) * self.P_FACTOR
for column in best_fit}) compared to before that fix: I'll gladly accept a PR for this, otherwise I'll fix that myself :) |
I can not provide a PR for this because I don't understand the details here. I understand your examples. But I would say that they doesn't matter for my problem. |
I disagree. Pandas' defaults are pretty useless. How is this useful in any way? You can't even tell on what column the headers is: import pandas as pd
pd.DataFrame({'a' * 100: []}).to_excel('output.xlsx') If the long content is in a row (ie not in the header) it looks a bit better, but still messy. I don't want StyleFrame's output to look this way, not even by default. |
I see your point and agree with you. You say "Pandas' defaults are pretty useless". From the viewpoint of StyleFrame you are right. That is where your StyleFrame comes in. It is its job. My initial problem was
I understand that StyleFrame tries and have to set some defaults for column widths. That is fine. I don't know how you manipulate the column width. But isn't it possible to manipulate the column width without making it a fixed width so that the "auto fit column width" feature doesn't work anymore? EDIT:
StyleFrame default behavior? Maybe this should be the same as Excels "auto fit": Fit column width to content and header. |
Different from
pandas.to_excel()
it seems to me thatStyelFrame.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
andC
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
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.
The text was updated successfully, but these errors were encountered: