textRotation 255 prevents import

Issue #363 resolved
Trevor Carlson created an issue

In 2.1, a restriction of 0-180 was placed on text rotation, which is usually fine. However, 255 is also a valid value. Repro:

  1. Create a new Excel file (I'm using 2013)
  2. put some text in a random cell, and go to format cells->alignment.
  3. Under Orientation, click the vertical word "Text". This changes "Text" to white on black, and sets the vertical alignment to "Bottom (Indent)".
  4. Save, and try to open in openpyxl.


Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 151, in load_workbook
    _load_workbook(wb, archive, filename, read_only, keep_vba)
  File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 205, in _load_workbook
    style_table, color_index, cond_styles = read_style_table(archive.read(ARC_STYLE))
  File "C:\Python27\lib\site-packages\openpyxl\reader\style.py", line 215, in read_style_table
  File "C:\Python27\lib\site-packages\openpyxl\reader\style.py", line 44, in parse
  File "C:\Python27\lib\site-packages\openpyxl\reader\style.py", line 191, in parse_cell_xfs
    _style['alignment'] = Alignment(**alignment)
  File "C:\Python27\lib\site-packages\openpyxl\styles\alignment.py", line 54, in __init__
    self.textRotation = textRotation
  File "C:\Python27\lib\site-packages\openpyxl\styles\hashable.py", line 54, in __setattr__
    return object.__setattr__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\openpyxl\descriptors\__init__.py", line 89, in __set__
    super(Min, self).__set__(instance, value)
  File "C:\Python27\lib\site-packages\openpyxl\descriptors\__init__.py", line 68, in __set__
    raise ValueError('Max value is {0}'.format(self.max))
ValueError: Max value is 180

Looking at the styles.xml, the resulting textRotation is, indeed, 255.

Comments (4)

  1. CharlieC

    I'm not sure what do about this as the specification is quite clear: """ text rotation in cells. Expressed in degrees. Values are in the range 0 to 180. The first letter of the text is considered the center-point of the arc. """ So, at first glance I would say that the bug is in Excel 2013 but it looks more like a bug in the specification.

  2. CharlieC

    I've asked the ECMA for guidance on what to do with this. The best solution would be to impose the limit as we do and have an extra control for "text-stacking" as OpenOffice/LibreOffice do. In the meantime you can monkey patch the code in openpyxl/styles/alignment.py by setting the max to 359

  3. Log in to comment