Column width returns 0.0 for some columns

Issue #1200 invalid
Kai B created an issue

I unzipped an xlsx and investigated the sheets1.xml.

In the section <cols> i found the following entry:

<col width="8.140625" style="96" min="7" max="10" customWidth="1" outlineLevel="1"/>

=> which coressponds to the col 7 to 10 in Excel. All Columns are visible and have the same size in Excel.

However, if i iterate through all columns via:

for i in range(sheet.max_column):
     column_letter = openpyxl.utils.cell.get_column_letter(i + 1)
     width = sheet.column_dimensions[column_letter].width
     print "Column %s: %s" % (column_letter, width)

i receive the following output:

Column G: 8.140625 Column H: 0.0 Column I: 0.0 Column J: 0.0

It seems like openpyxl doesn't take in account, that the width for all 4 columns is specified in one entry within the xml.

I checked with latest commit of 2.6 branch.

Comments (2)

  1. CharlieC

    If you iterate like this you openpyxl will create new column dimensions objects on-demand; this is so that you can add them more easily. If you only want to look at the ones created, you'll need to loop over the .keys() or .items()

  2. Log in to comment