sheets are out of order

Issue #209 resolved
Mark Mikofski created an issue

expected: load sheets by name, they should correspond to the named sheets in the file

observed: unfortunately, the sheet names are unreliable, The order in which they are listed is the same as the actual workbook, but the names are mixed up. IE: the first sheet in the book is still the first sheet in the array, but it's name may or not be the same, so that using get_sheet_by_name, may not work.

It seems that if the workbook has charts as sheets, then there names will get loaded.


'work' has sheet1: 'hello' sheet2: 'graph1' (a chart) sheet3: 'bye'

>>> wb = load_workbook('work')
>>> wb.get_sheet_names()
['hello', 'graph1', 'bye']

see the problem!

Comments (6)

  1. CharlieC

    See #165 - the problem is that we can't handle sheets that are charts. I think someone has submitted a pull request which at least starts to address this.

  2. Eric Gazoni

    fixes issue #165, #179 and #209

    • add function read_content_types to openpyxl/reader/ that reads all of the 'Override' items in [Content_Types].xml
    • import ARC_CONTENT_TYPES and read_content_types into openpyxl/reader/
    • create constants VALID_CHARTSHEET and VALID_WORKSHEET that have the ContentType tag specified in [Content_Types].xml for chartsheets and worksheets
    • call read_content_types immediately before read_sheet_titles
    • before iterating over sheet_names create new list called worksheet_names that contains only the list of sheets that are actually worksheets, by comparing their type to VALID_WORKSHEET
    • import basic debug logging, use standard message format (from Doug Hellmann) ""
    • add show_debug_log optional arg to load_workbook & pass it on to Lload_workbook
    • add Sphinx autodoc text for show_debug_log
    • if show_debug_log, then output name of each worksheet before it's loaded

    → <<cset 498594f25594>>

  3. Log in to comment