[GH-ISSUE #67] Improve documentation about column width unit #60

Closed
opened 2026-05-05 11:34:48 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @lemmel on GitHub (Jul 19, 2016).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/67

Could you add something about the unit used when setting (e.g. through the worksheet_set_column_opt function) the width of a column ?

It is not cm, mm, inch, pica because when I looked for information about it, I found :

I quote the ISO document:

Column width measured as the number of characters of the maximum digit width of the
numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin
padding (two on each side), plus 1 pixel padding for the gridlines.

So to be sure of a column width, the developper must define the default font and set the width accordingly.

P.S. :

  • I'm not sure about it, but it seems that the Excel vanilla default font is Calibri, style Normal, Size 11. I don't know for sure that user settings can not change that value (i.e. that the value is per document)
  • libreoffice, and probably openoffice, under Linux do strange things with width, and don't get the good width.
Originally created by @lemmel on GitHub (Jul 19, 2016). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/67 Could you add something about the unit used when setting (e.g. through the worksheet_set_column_opt function) the width of a column ? It is not cm, mm, inch, pica because when I looked for information about it, I found : - http://ericwhite.com/blog/precisely-calculating-cell-sizes-in-open-xml-spreadsheetml/ (precisely at https://youtu.be/zgO_vOfThCI?t=238) - ISO/IEC 29500-1:2012 (can be found: http://standards.iso.org/ittf/PubliclyAvailableStandards/index.html) I quote the ISO document: > Column width measured as the number of characters of the maximum digit width of the > numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin > padding (two on each side), plus 1 pixel padding for the gridlines. So to be sure of a column width, the developper must define the default font and set the width accordingly. P.S. : - I'm not sure about it, but it seems that the Excel vanilla default font is Calibri, style Normal, Size 11. I don't know for sure that user settings can not change that value (i.e. that the value is per document) - libreoffice, and probably openoffice, under Linux do strange things with width, and don't get the good width.
gitea-mirror 2026-05-05 11:34:48 -06:00
Author
Owner

@jmcnamara commented on GitHub (Jul 19, 2016):

Hi,

This is explained a little better in the docs for the Python version of this library:

The width parameter sets the column width in the same units used by Excel which is: the number of characters in the default font. The default width is 8.43 in the default font of Calibri 11. The actual relationship between a string width and a column width in Excel is complex. See the following explanation of column widths from the Microsoft support documentation for more details.

I'll port that, and the other updated text, to the C docs.

John

<!-- gh-comment-id:233637744 --> @jmcnamara commented on GitHub (Jul 19, 2016): Hi, This is explained a little better in the docs for the [Python version of this library](http://xlsxwriter.readthedocs.io/worksheet.html#worksheet-set-column): > The width parameter sets the column width in the same units used by Excel which is: the number of characters in the default font. The default width is 8.43 in the default font of Calibri 11. The actual relationship between a string width and a column width in Excel is complex. See the following explanation of column widths from the [Microsoft support documentation for more details](https://support.microsoft.com/en-us/kb/214123). I'll port that, and the other updated text, to the C docs. John
Author
Owner

@jmcnamara commented on GitHub (Jul 19, 2016):

I've pushed a update to master and regenerated the online docs.

Thanks for the report.

Closing.

John

<!-- gh-comment-id:233791613 --> @jmcnamara commented on GitHub (Jul 19, 2016): I've pushed a update to master and regenerated the online docs. Thanks for the report. Closing. John
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#60
No description provided.