I have a class that reads two different Excel workbooks and ran into this bug.
SOURCE = "path to an excel file"
TFXREF = "path to another excel file"
from xlrd import open_workbook
class Reader(object):
def __init__(self):
s = open_workbook(SOURCE)
for sheet in s.sheets():
print sheet
t = open_workbook(TFXREF)
print t.get_sheet(0)
r = Reader()
I run this code (with the proper paths built in) and get:
<xlrd.sheet.Sheet object at 0x05E52D10>
<xlrd.sheet.Sheet object at 0x05EDD670>
<xlrd.sheet.Sheet object at 0x05EF2630>
<xlrd.sheet.Sheet object at 0x05F45930>
Traceback (most recent call last):
File "<string>", line 254, in run_nodebug
File "C:\Users\josh\Desktop\xlrdbug.py", line 18, in <module>
r = Reader()
File "C:\Users\josh\Desktop\xlrdbug.py", line 14, in __init__
print t.get_sheet(0)
File "C:\Users\josh\Desktop\Portable Python\App\lib\site-packages\xlrd\book.py", line 682, in get_sheet
raise XLRDError("Can't load sheets after releasing resources.")
xlrd.biffh.XLRDError: Can't load sheets after releasing resources.
The first book has four sheets. the second book only has one.
I can get around this by iterating through the sheets of the second book, but this seems silly when I know there is only one sheet.
I upgraded xlrd to 0.9.2 and still get this issue.
josh