Passing Row/Column Dimension `"s"` argument raises TypeError: int object is not iterable

Issue #1120 invalid
Benjamin Hauch
created an issue

Python 3.6 x64 & openpyxl 2.5.9

MCVE:

from openpyxl.worksheet.dimensions import RowDimension
source_format = {
    "s": 0,
}
ws = wb.active
rd = RowDimension(ws, **source_format)

Stack Trace:

  File ".....\openpyxl\worksheet\dimensions.py", line 110, in __init__
    collapsed, worksheet, style=s)
  File ".....\openpyxl\worksheet\dimensions.py", line 44, in __init__
    super(Dimension, self).__init__(sheet=worksheet, style_array=style)
  File ".....\openpyxl\styles\styleable.py", line 132, in __init__
    style_array = StyleArray(style_array)
  File ".....\openpyxl\styles\cell_style.py", line 54, in __new__
    return array.__new__(cls, 'i', args)
TypeError: 'int' object is not iterable

I believe this bug dates to commit https://bitbucket.org/openpyxl/openpyxl/commits/c7adaff88e544de833938382ffaf018b5ee260f2 which changed the initialization of the Dimension class, passing s to the StyleArray constructor even though s is the style_id - explicitly an int and not an iterable.

Comments (2)

  1. CharlieC

    I don't really understand what you're trying to do here. s as integer is really implementation detail relating to how the stuff is serialised as XML. The openpyxl API presents a StyleableObject where you set formats directly. Also, Dimension objects should be obtained already bound to the worksheet from the relevant collection.

  2. Log in to comment