Call save,Prompt list index out of range

Issue #781 resolved
xiaoqi7s created an issue

import openpyxl path = r'C:\Users\hcb\Desktop\test.xlsx' wb = openpyxl.load_workbook(path) wb.save('test.xlsx')

Traceback (most recent call last): File "D:/python3/test1/myPackge/test2.py", line 4, in wb.save('test.xlsx') File "C:\Python36\lib\site-packages\openpyxl\workbook\workbook.py", line 342, in save save_workbook(self, filename) File "C:\Python36\lib\site-packages\openpyxl\writer\excel.py", line 267, in save_workbook writer.save(filename) File "C:\Python36\lib\site-packages\openpyxl\writer\excel.py", line 248, in save self.write_data() File "C:\Python36\lib\site-packages\openpyxl\writer\excel.py", line 81, in write_data self._write_worksheets() File "C:\Python36\lib\site-packages\openpyxl\writer\excel.py", line 197, in _write_worksheets xml = ws._write() File "C:\Python36\lib\site-packages\openpyxl\worksheet\worksheet.py", line 870, in _write return write_worksheet(self) File "C:\Python36\lib\site-packages\openpyxl\writer\worksheet.py", line 99, in write_worksheet cols = ws.column_dimensions.to_tree() File "C:\Python36\lib\site-packages\openpyxl\worksheet\dimensions.py", line 230, in to_tree obj = col.to_tree() File "C:\Python36\lib\site-packages\openpyxl\worksheet\dimensions.py", line 182, in to_tree attrs = dict(self) File "C:\Python36\lib\site-packages\openpyxl\worksheet\dimensions.py", line 51, in iter value = getattr(self, key, None) File "C:\Python36\lib\site-packages\openpyxl\styles\styleable.py", line 95, in get return coll.names[idx] IndexError: list index out of range

Comments (15)

  1. liuyuqian

    找找自己的原因吧。。。这么基本的功能肯定没问题啊,我也试了,没问题

  2. CharlieC

    Sorry but I can't read Mandarin. I suspect that the source file is from LibreOffice and is itself invalid.

  3. CharlieC

    What same problem? Looks like a duplicate of #647 to me but without any files and error messages in English I cannot investigate further.

  4. xxxxxxxiao

    I just simply load a xlsx file and then save it. Loading the xlsx file works find but when i called wb.save i had the same error as above

  5. xiaoqi7s reporter

    My file is exported by java and provided by developer so i guess that the file is LibreOffice.

  6. CharlieC

    Thanks for the file. The problem is somewhat related to the redundant styles that LibreOffice tends to create but I think I've fixed it.

  7. Sebastian Koslowski

    Unfortunately, I seem to now get a possibly related error when loading a file:

      File "/home/koslowski/code/klausur_tool/cel_klausur_tool/database/exam.py", line 31, in __init__
        self._wb = openpyxl.load_workbook(filename)
      File "/opt/miniconda3/envs/klausur-tool/lib/python3.5/site-packages/openpyxl/reader/excel.py", line 238, in load_workbook
        ws_parser.parse()
      File "/opt/miniconda3/envs/klausur-tool/lib/python3.5/site-packages/openpyxl/reader/worksheet.py", line 125, in parse
        dispatcher[tag_name](element)
      File "/opt/miniconda3/envs/klausur-tool/lib/python3.5/site-packages/openpyxl/reader/worksheet.py", line 287, in parser_conditional_formatting
        rule.dxf = self.differential_styles[rule.dxfId]
      File "/opt/miniconda3/envs/klausur-tool/lib/python3.5/site-packages/openpyxl/styles/differential.py", line 96, in __getitem__
        return self.styles[idx]
    IndexError: list index out of range
    
  8. CharlieC

    @skoslowski that looks like a separate issue. Please create a new ticket and provide a sample file.

  9. Log in to comment