0

Is there way to auto-size (auto-fit) the width based on cell contents for the entire worksheet.

sheet.column_dimensions['A'].width=number

I am not looking for the above, for which you have to specify the column. Is there a way to set it up with "openpyxl"?

Jongware
  • 21,685
  • 8
  • 47
  • 95
Jay
  • 7
  • 2
  • 1
    ***"way to auto-size (auto-fit)"***: Not implemented in `openpyxl`. Relevant [`[python][openpyxl] column width`](https://stackoverflow.com/search?q=isanswered%3Ayes+is%3Aquestion+%5Bpython%5D%5Bopenpyxl%5D+column+width) – stovfl Feb 12 '20 at 08:50
  • You indeed could have found this yourself. It is a known – and *closed* – issue: https://bitbucket.org/openpyxl/openpyxl/issues/1275/auto_size-and-bestfit-not-working – Jongware Feb 12 '20 at 18:39
  • 1
    https://stackoverflow.com/questions/13197574/openpyxl-adjust-column-width-size – Johnny Metz Feb 12 '20 at 22:22

1 Answers1

-3

If you simply want to set the width to some "number", just loop over it (to the max column), If you need to set the width for each column specifically tailored to the contents of that(!) column, I think that is not possible with openpyxl (sadly).

TylerH
  • 20,816
  • 57
  • 73
  • 92
rt87
  • 863
  • 6
  • 7