1

I use openpyxl library on my backend server(Ubuntu 64bit) for generating excel documents with a bit of styles and it well working when user open generated file in Linux. If someone open file on Windows column width are crashed.

How to make that excel styles making in openpyxl well working both on Linux and Windows?

A bit Example how it shows the file: On linux enter image description here

and Windows enter image description here

I count on your help :)

  • Looks to me just the column widths are wrong, or am I missing something? Either way, I wouldn't count on much luck with M$ formats playing well with others. – bosnjak Feb 24 '17 at 21:18
  • So that`s the problem :) Columns width show different size depends on operating system. It is the same file but opened with different OS – Александр Веклич Feb 24 '17 at 21:26
  • I'm afraid there's nothing you can do about it. But keep looking and good luck :) – bosnjak Feb 24 '17 at 21:27
  • Please post the section of code you are using to set the column widths. – Alan Feb 24 '17 at 21:58
  • I think with openpyxl you can set the column width of each column. However you can not auto-set the column width, only Excel itself can do that. – Elmex80s Feb 25 '17 at 02:04
  • I use [this](http://stackoverflow.com/questions/13197574/python-openpyxl-column-width-size-adjust) solution for auto expand width in column depends on string length. It`s work perfectly on computers with Linux OS, but not on Windows – Александр Веклич Feb 25 '17 at 20:56

2 Answers2

0

Column widths are OS-specific and, hence, you can never get the same sizing on different OSes: OS DPI and font-rendering specifics make this impossible.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55
0

I have used this code for adjusting columns width. It is in windows

for column_cells in sheet.columns:
    new_column_length = max(len(str(cell.value)) for cell in column_cells)
    new_column_letter = (get_column_letter(column_cells[0].column))
    if new_column_length > 0:
        sheet.column_dimensions[new_column_letter].width = new_column_length*1.23
Mounesh
  • 561
  • 5
  • 18