'Strict Open XML Spreadsheet' format cause 'UnboundLocalError: local variable 'sheet_id' referenced before assignment'

Issue #577 on hold
smwikipedia smwikipedia created an issue

I use Excel 2013 to save a spreadsheet as Strict Open XML Spreadsheet (*.xlsx) format. Shown as below:

strict open xml format.png

Then I run the following round trip test:

    wb = load_workbook(filename=r'D:\strict_test.xlsx')

It throws the following error:

  File "C:\DevTools\Python\Python27x86\lib\site-packages\openpyxl\workbook\workbook.py", line 263, in save
    save_workbook(self, filename)
  File "C:\DevTools\Python\Python27x86\lib\site-packages\openpyxl\writer\excel.py", line 239, in save_workbook
    writer.save(filename, as_template=as_template)
  File "C:\DevTools\Python\Python27x86\lib\site-packages\openpyxl\writer\excel.py", line 222, in save
    self.write_data(archive, as_template=as_template)
  File "C:\DevTools\Python\Python27x86\lib\site-packages\openpyxl\writer\excel.py", line 98, in write_data
    manifest = write_content_types(self.workbook, as_template=as_template, exts=exts)
  File "C:\DevTools\Python\Python27x86\lib\site-packages\openpyxl\packaging\manifest.py", line 197, in write_content_types
    for sheet_id, sheet in enumerate(workbook.chartsheets, sheet_id+1):
**UnboundLocalError: local variable 'sheet_id' referenced before assignment**

The related code is this:

    for sheet_id, sheet in enumerate(workbook.chartsheets, sheet_id+1):

While if I save the spread sheet as Excel Workbook (*.xlsx). No error is thrown.

I think we should support Strict Open XML Spreadsheet format.

Comments (9)

  1. CharlieC

    Who is we?

    This is a known issue: the strict implementation uses a completely different namespace. We'll need some way to switch safely between the transitional and strict namespaces.

  2. smwikipedia smwikipedia reporter

    I am new to git system. I will learn to use it and create the pull request.

  3. Log in to comment