Expand columns to needed width

38 views
Skip to first unread message

c.b...@posteo.jp

unread,
Sep 9, 2021, 9:03:00 AM9/9/21
to openpyx...@googlegroups.com
Hello together,

I create xlsx-files with pandas via openpyxl.

The columns of the resulting xlsx files are to small for the content. I
have to adjust them via Excel.

Does openpyxl support visual things (e.g. cell higth, width, colors,
fonts, ...) like this or is it just for the content?

Thanks
Christian

Polly

unread,
Sep 9, 2021, 9:09:22 AM9/9/21
to openpyxl-users
Hi Christian, I am still trying to figure out some stuff for openpyxl and column widths, but yes; if you check OpenXML documentation (https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.column?view=openxml-2.8.1) - search for width; almost all stuff in OpenXML are available in openpyxl thought not always document, so you need dive into the library code; checkout worksheet column_dimensions ; if your column does not have a custom width set, u need to find the default width which is available at worksheet sheet_format defaultColWidth
Like I said though, the col width is a weird one, i am not sure if it is given in pixel, points or other unit... colors and fonts, debug and see what the Cell object has; again whatever u find in OpenXML documentation most of it is somewhere in the code of openpyxl; good luck!

Charlie Clark

unread,
Sep 9, 2021, 11:42:02 AM9/9/21
to openpyx...@googlegroups.com
The documentation will tell you.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Waldlehne 23
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226
Reply all
Reply to author
Forward
0 new messages