Error on opening and saving xlsx file twice in a row

Issue #713 duplicate
AuckeBos created an issue

Code:

import openpyxl

file = openpyxl.load_workbook("test.xlsx") file.save("test.xlsx")

I've got a well working excel sheet. Opening it with openpyxl works fine. But when I run this code twice, I get the following error:

Traceback (most recent call last): File "openpyxlTest.py", line 3, in <module> file = openpyxl.load_workbook("test.xlsx") File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 201, in load_workbook apply_stylesheet(archive, wb) # bind styles to workbook File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 164, in apply_stylesheet stylesheet = Stylesheet.from_tree(node) File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 99, in from_tree return super(Stylesheet, cls).from_tree(node) File "/usr/local/lib/python2.7/dist-packages/openpyxl/descriptors/serialisable.py", line 89, in from_tree return cls(**attrib) File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 90, in init self.named_styles = self._merge_named_styles() File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 110, in _merge_named_styles xf = self.cellStyleXfs[style.xfId] File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/cell_style.py", line 182, in getitem return self.xf[idx] IndexError: list index out of range

I'm running on Linux mint, and used LibreOffice Calc to create this file. If I open and save the file using LibreOffice Calc in between the 2 calls, the second one works fine. Is this issue encountered only by me? It looks like a bug in the package.

The excel file contains only 1 sheet, which is empty.

Comments (5)

  1. Pedro Lobo

    Hello,

    I'm having the same problem. Using the same code from the python script provided by AuckeBos.

    I open a file and I save it again with the same, try to open it a second time and it gives me the "list index out of range" error.

    The only way I can open it again through python is if I open it with libre office, press the save button and close it, after this I can re-open the file again in the script, but when I save it again in the script, it goes back to the error.

    I'm running Ubuntu 16.04 64 bits and also using Libre Office (Version: 5.1.4.2)

    Python --version = 3.5.2

    pip3 list: apt-xapian-index (0.47) apturl (0.5.2) beautifulsoup4 (4.4.1) blinker (1.3) Brlapi (0.6.4) chardet (2.3.0) checkbox-support (0.22) command-not-found (0.3) cryptography (1.2.3) defer (1.0.6) et-xmlfile (1.0.1) feedparser (5.1.3) guacamole (0.9.2) html5lib (0.999) httplib2 (0.9.1) idna (2.0) jdcal (1.3) Jinja2 (2.8) language-selector (0.1) louis (2.6.4) lxml (3.6.4) Mako (1.0.3) MarkupSafe (0.23) oauthlib (1.0.3) onboard (1.2.0) oneconf (0.3.9) openpyxl (2.4.0) padme (1.1.1) pexpect (4.0.1) Pillow (3.1.2) pip (8.1.2) piston-mini-client (0.7.5) plainbox (0.25) ptyprocess (0.5) pyasn1 (0.1.9) pycrypto (2.6.1) pycups (1.9.73) pycurl (7.43.0) pygobject (3.20.0) PyJWT (1.3.0) pyparsing (2.0.3) python-apt (1.1.0b1) python-debian (0.1.27) python-systemd (231) pyxdg (0.25) reportlab (3.3.0) requests (2.9.1) sessioninstaller (0.0.0) setuptools (20.7.0) six (1.10.0) software-center-aptd-plugins (0.0.0) system-service (0.3) ubuntu-drivers-common (0.0.0) ufw (0.35) unattended-upgrades (0.1) unity-scope-calculator (0.1) unity-scope-chromiumbookmarks (0.1) unity-scope-colourlovers (0.1) unity-scope-devhelp (0.1) unity-scope-firefoxbookmarks (0.1) unity-scope-gdrive (0.7) unity-scope-manpages (0.1) unity-scope-openclipart (0.1) unity-scope-texdoc (0.1) unity-scope-tomboy (0.1) unity-scope-virtualbox (0.1) unity-scope-yelp (0.1) unity-scope-zotero (0.1) urllib3 (1.13.1) usb-creator (0.3.0) wheel (0.29.0) xdiagnose (3.8.4.1) xkit (0.0.0) XlsxWriter (0.7.3)

  2. Log in to comment