Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the column width using openpyxl? [closed]

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?

like image 941
graffe Avatar asked Dec 23 '18 19:12

graffe


People also ask

How do I change the column width in Openpyxl?

Set the width of a column by calling the Cells collection's setColumnWidth method. The setColumnWidth method takes the following parameters: Column index, the index of the column that you're changing the width of. Column width, the desired column width.

How can you automatically adjust the width of a column to fit the size of the longest entry?

You can quickly adjust the column width to accommodate the longest entry. Select any column from the worksheet. From the Cells group on the Home tab, choose Format. Select AutoFit Column Width to set that column to auto-fit the width depending on the contents.

What is difference between Openpyxl and XlsxWriter?

XlsxWriter vs openpyxl: What are the differences? Developers describe XlsxWriter as "A Python module for creating Excel XLSX files". A Python module for creating Excel XLSX files. On the other hand, openpyxl is detailed as "A Python library to read/write Excel 2010 xlsx/xlsm files".


1 Answers

Openpyxl column width

ws.column_dimensions['A'].width = 25
like image 129
ycx Avatar answered Sep 24 '22 01:09

ycx