auto_size and bestFit not working

Issue #1275 closed
Ian Lee created an issue

I have tried to use auto_size and bestFit to set the column widths, but the result is all my columns' width are set to 0. Is this a bug or am I doing something wrong?

for column_cell in ws.columns:
  ws.column_dimensions[get_column_letter(column_cell[0].column)].auto_size = True

Comments (4)

  1. CharlieC

    Unfortunately, you must always set column widths manually as the default is 0. The bestFit attribute is essentially a note for the application that is rendering the worksheet.

  2. CharlieC

    No, there isn’t. The specification contains a formula for doing this that is dependent upon things like the system DPI and the typeface being used, ie. this up to the application displaying the worksheet. Basically: turn everything in a column into a string and use the length of the widest.

  3. Log in to comment