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

Anyway to autosize columns? #55

Open
ronnyek opened this issue Oct 29, 2024 · 3 comments
Open

Anyway to autosize columns? #55

ronnyek opened this issue Oct 29, 2024 · 3 comments
Labels
question Further information is requested

Comments

@ronnyek
Copy link

ronnyek commented Oct 29, 2024

I generate xlsx files, and all works well, but by default columns are minimal width, and I don't have anyway to know what is ideal length.

I'm wondering if there is anyway I can automatically size them based on the text content within?

@vitaliy-nerdysoft
Copy link

vitaliy-nerdysoft commented Nov 7, 2024

@ronnyek, That`s the only reason I need a library for Excel native file generation. Please let me know if you found a solution for that?

@dgosbell
Copy link

dgosbell commented Nov 7, 2024

In this library you need to specify the column widths when creating the worksheet see https://github.com/salvois/LargeXlsx?tab=readme-ov-file#column-formatting so to set the size based on the content you would need to loop through your data and calculate the string width based off the formatting using a technique like one of the ones suggested here https://stackoverflow.com/questions/263614/calculate-the-display-width-of-a-string-in-c to find the maximum size. There is no magic autosize setting.

@salvois salvois added the question Further information is requested label Nov 10, 2024
@salvois
Copy link
Owner

salvois commented Nov 10, 2024

Thanks everyone. This question keeps popping up so it definitely deserves attention, maybe adding a FAQ or a note in the documentation.
By the way, there is a bestFit attribute on the column element that would serve as a hint for spreadsheet applications to enlarge columns automatically when content is input, but last time I checked it didn't work as requested by @ronnyek . I feel like it's worth double checking though. Will let you know.

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

No branches or pull requests

4 participants