Skip to content
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

Column attribute best_fit is not set correctly #377

Open
zerowaitstate opened this issue Apr 30, 2024 · 2 comments
Open

Column attribute best_fit is not set correctly #377

zerowaitstate opened this issue Apr 30, 2024 · 2 comments

Comments

@zerowaitstate
Copy link

There is a serializable attribute on worksheet columns called best_fit which tells excel whether to automatically resize a column. This is apparently set to "true" when the column width is manually set via width=. This would seem to be opposite the expected behavior, especially when considering the attribute documentation on best_fit. I checked back through the commit history and this is not a regression; this bug seems to have been there since the original column code was written.

@custom_width = @best_fit = !v.nil?

Before doing a PR I wanted to ask if I am possibly misunderstanding what this attribute does.

@zerowaitstate
Copy link
Author

zerowaitstate commented Apr 30, 2024

This is the doc on the attribute

# Flag indicating if the specified column(s) is set to 'best fit'. 'Best fit' is set to true under these conditions:
# The column width has never been manually set by the user, AND The column width is not the default width
# 'Best fit' means that when numbers are typed into a cell contained in a 'best fit' column, the column width should
# automatically resize to display the number. [Note: In best fit cases, column width must not be made smaller, only larger. end note]

@kiskoza
Copy link
Member

kiskoza commented May 2, 2024

Hi @zerowaitstate. Let me know if I get it right: the best_fit attribute does not have an instant visual effect, but it defines how the cell should handle when you edit it later and provide a long(er) number.

By default, Excel has "best fit" as true on every cell, you can try it out with an empty sheet. I think the original code meant to keep this behaviour for caxlsx generated cells with pre-calculated widths. It looks like the comments are describing how Excel uses this flag, not how caxlsx is trying to set it.

I can see your point on why do you want to turn this off, so I'd suggest adding a global config to caxlsx to auto-enable best fit or not (default should be the current behaviour). We're doing something similar with No autowidth config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants