Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

Raise exception in Workbook.save() when saving a workbook with no worksheets #133

Closed
wants to merge 1 commit into from

Conversation

mapellegrini
Copy link

I ran into this problem when learning how to use xlwt. Currently it throws an unhelpful index error:

import xlwt
wb=xlwt.Workbook()
wb.save("/tmp/test.xls")
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/xlwt/Workbook.py", line 710, in save
doc.save(filename_or_stream, self.get_biff_data())
File "/usr/local/lib/python2.7/dist-packages/xlwt/Workbook.py", line 680, in get_biff_data
self.__worksheets[self.__active_sheet].selected = True
IndexError: list index out of range

@coveralls
Copy link

coveralls commented Mar 22, 2018

Coverage Status

Coverage decreased (-0.003%) to 59.507% when pulling 179c87e on mapellegrini:master into 0fc028f on python-excel:master.

@mapellegrini
Copy link
Author

Here is the relevant test (carried out on xlwt as cloned from my github repo to /tmp):

import sys
sys.path=["/tmp/xlwt"] + sys.path
import xlwt
wb=xlwt.Workbook()
wb.save("/tmp/test.xls")
Traceback (most recent call last):
File "", line 1, in
File "/tmp/xlwt/xlwt/Workbook.py", line 710, in save
raise Exception("Can't save a workbook that contains no worksheets")
Exception: Can't save a workbook that contains no worksheets

@jdufresne
Copy link
Contributor

jdufresne commented Apr 8, 2018

Thanks for the contribution. Can you add a test to tests/ please?

@cjw296 cjw296 closed this May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants