Loading xlsx workbook generated by Numbers fails

Issue #359 resolved
Alex Rattray created an issue

When I try to load_workbook an xlsx file generated by OSX's Numbers program, I get the following traceback:

In [3]: openpyxl.load_workbook('_data/members_old.xlsx')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-3354b165584b> in <module>()
----> 1 openpyxl.load_workbook('_data/members_old.xlsx')

/usr/local/lib/python2.7/site-packages/openpyxl/reader/excel.pyc in load_workbook(filename, use_iterators, keep_vba, guess_types, data_only)
    163
    164     try:
--> 165         _load_workbook(wb, archive, filename, use_iterators, keep_vba)
    166     except KeyError:
    167         e = exc_info()[1]

/usr/local/lib/python2.7/site-packages/openpyxl/reader/excel.pyc in _load_workbook(wb, archive, filename, use_iterators, keep_vba)
    210         assert wb.loaded_theme == None, "even though the theme information is missing there is a theme object ?"
    211
--> 212     style_properties = read_style_table(archive.read(ARC_STYLE))
    213     style_table = style_properties.pop('table')
    214     wb.shared_styles = style_properties.pop('list')

/usr/local/lib/python2.7/site-packages/openpyxl/reader/style.pyc in read_style_table(xml_source)
    220 def read_style_table(xml_source):
    221     p = SharedStylesParser(xml_source)
--> 222     p.parse()
    223     return p.style_prop

/usr/local/lib/python2.7/site-packages/openpyxl/reader/style.pyc in parse(self)
     41         self.border_list = list(self.parse_borders())
     42         self.parse_dxfs()
---> 43         self.parse_cell_xfs()
     44
     45     def parse_custom_num_formats(self):

/usr/local/lib/python2.7/site-packages/openpyxl/reader/style.pyc in parse_cell_xfs(self)
    201
    202             if bool(cell_xfs_node.get('applyFill')):
--> 203                 _style['fill'] = self.fill_list[int(cell_xfs_node.get('fillId'))].copy()
    204
    205             if bool(cell_xfs_node.get('applyBorder')):

TypeError: int() argument must be a string or a number, not 'NoneType'

Comments (10)

  1. Alex Rattray reporter

    In this case, I just downloaded a version of the spreadsheet from Google Docs and it worked fine.

  2. CharlieC

    It's worth noting that the file can't actually be inspected or validated by the official Office OpenXML SDK tool.

  3. Alex Rattray reporter

    Ah, gotcha. I'd mark as a wontfix then. Consider making a note in the
    documentation though?

    Thanks for looking into this!

  4. CharlieC

    Okay, you should now be able to work with the file. The formatting has gone to hell because we don't support user styles yet. I also noticed that there was an image in the archive. Needless to say that we don't yet support importing images either- ;-)

  5. Alex Rattray reporter

    Wow, well done! Thanks!
    Funny about the image, I didn't include it... I think Numbers might just do that sometimes.

  6. Log in to comment