Querying column_dimensions can have unexpected behaviour

Issue #1114 resolved
Liam Sanders created an issue

This could entirely be user error, but I wanted to check if a column has a custom width set, and if it does perform some action on it. See attached script.

What happens though is if the column does not have a custom width, then by querying column_dimensions["E"].customWidth, it correctly returns False but a column_dimension is created with all None/empty values which results in the final sheet having that column basically hidden.

I worked around it by checking if my column exists in column_dimensions.keys() but that seemed sort of counter intuitive.

I think it would be better if there was some way of querying if custom column/row attributes had been set that doesn't create an empty one in the process.

Comments (5)

  1. CharlieC

    Thanks for the report. Actually this is probably a bug as dimension objects shouldn't be serialised if they don't contain any values, though Excel is also reading the values in correctly: the column is marked as not having a custom width and, therefore, the base (8) should apply.

  2. Log in to comment