[GH-ISSUE #307] Automatic column width #248

Closed
opened 2026-05-05 12:02:05 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @gufoe on GitHub (Sep 16, 2020).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/307

Originally assigned to: @jmcnamara on GitHub.

Hello, is there any way to set the column width to automatically adjust with its content?

Originally created by @gufoe on GitHub (Sep 16, 2020). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/307 Originally assigned to: @jmcnamara on GitHub. Hello, is there any way to set the column width to automatically adjust with its content?
gitea-mirror 2026-05-05 12:02:05 -06:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jmcnamara commented on GitHub (Sep 16, 2020):

Unfortunately, there is no way to specify "AutoFit" for a column in the Excel file format. This feature is only available at runtime from within Excel. So it isn't something that we be done be the library.

The only workaround would be to try track the width of the data as you write it and then size the columns based on that. However, even that isn't easy without access to some functions that would given you a pixel, or other, length for a string in a particular font. If you are on Windows you might have that but on other platforms it isn't easy.

<!-- gh-comment-id:693322562 --> @jmcnamara commented on GitHub (Sep 16, 2020): Unfortunately, there is no way to specify "AutoFit" for a column in the Excel file format. This feature is only available at runtime from within Excel. So it isn't something that we be done be the library. The only workaround would be to try track the width of the data as you write it and then size the columns based on that. However, even that isn't easy without access to some functions that would given you a pixel, or other, length for a string in a particular font. If you are on Windows you might have that but on other platforms it isn't easy.
Author
Owner

@gufoe commented on GitHub (Sep 16, 2020):

Ok, thank you for the info!

<!-- gh-comment-id:693502165 --> @gufoe commented on GitHub (Sep 16, 2020): Ok, thank you for the info!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#248
No description provided.