11

I have xlsx format spreadsheets. For each one I need to set the column width for all but one column to 25 and the width of the remaining column to 50. The unit of measurement is the idiosyncratic one Excel uses.

The spreadsheets are originally produced in Google sheets which has no way to do this so currently I have to download them in xlsx format and then email them to a friend who has Excel to have them fixed as I don't own a copy of Excel myself. This is clearly far from ideal.

Is it possible to set the column widths using openpyxl?

6
  • Always helps if you look at the documentation. Commented Dec 24, 2018 at 15:52
  • @CharlieClark True. I find the different units very confusing. Commented Dec 24, 2018 at 15:53
  • They are confusing because they are OS and device specific but they are covered by the OOXML specification and not the repsonsibility of openpyxl. Commented Dec 24, 2018 at 15:55
  • @CharlieClark In openpyxl how do you specify if the width is in points, pixels, or the default Excel units? Commented Dec 24, 2018 at 15:57
  • The units are related to the width of the widest character in the typeface being used. For further information please refer to the OOXML specification. Commented Dec 24, 2018 at 15:58

1 Answer 1

47

Openpyxl column width

ws.column_dimensions['A'].width = 25
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.