Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open_workbook throws KeyError(None) when workbook contains sheet with rId being None #48

Open
pallxk opened this issue Aug 27, 2023 · 2 comments · May be fixed by #49
Open

open_workbook throws KeyError(None) when workbook contains sheet with rId being None #48

pallxk opened this issue Aug 27, 2023 · 2 comments · May be fixed by #49

Comments

@pallxk
Copy link

pallxk commented Aug 27, 2023

When a workbook contains sheet with rId being None, open_workbook throws KeyError(None).

Related code:

for item in reader:
if item[0] == biff12.SHEET:
self._sheets.append((item[1].name, rels[item[1].rId]))
elif item[0] == biff12.SHEETS_END:
break

And some debug output:

for item in reader:
  print(item)

(387, 'workbook')
(399, 'sheets')
(412, sheet(sheetId=28, rId=None, name=None))
(412, sheet(sheetId=2, rId='rId1', name='*'))
(412, sheet(sheetId=13, rId='rId2', name='*'))
(412, sheet(sheetId=15, rId='rId3', name='*'))
(412, sheet(sheetId=16, rId='rId4', name='*'))
(412, sheet(sheetId=23, rId='rId5', name='*'))
(412, sheet(sheetId=21, rId='rId6', name='*'))
(412, sheet(sheetId=22, rId='rId7', name='*'))
(412, sheet(sheetId=18, rId='rId8', name='*'))
(412, sheet(sheetId=25, rId='rId9', name='*'))
(412, sheet(sheetId=7, rId='rId10', name='*'))
(412, sheet(sheetId=24, rId='rId11', name='*'))
(412, sheet(sheetId=27, rId='rId12', name='*'))
(412, sheet(sheetId=11, rId='rId13', name='*'))
(412, sheet(sheetId=5, rId='rId14', name='*'))
(400, '/sheets')

(I've masked all sheet names with values as '*'.)

For now, I don't know how to recreate such a *.xlsb file from scratch, and can't share the file I have due to confidentiality reasons. Hopefully the debug output is enough for anyone interested to identify the problem.

@pallxk pallxk linked a pull request Aug 27, 2023 that will close this issue
@pallxk pallxk changed the title open_workbook throws KeyError(None) when workbook contains sheet with rId == None open_workbook throws KeyError(None) when workbook contains sheet with rId being None Aug 27, 2023
@willtrnr
Copy link
Owner

Do you know where that workbook is coming from? Was it generated by Excel or some other application?

I'd have to recheck it, but I don't think this is valid per the MS-XLSB spec, so it could be a bug in the data reader or it could just genuinely be a corrupted file.

@pallxk
Copy link
Author

pallxk commented Aug 31, 2023

I believe It's generated/created with Excel and edited with it but I'm not sure how it evolves into that state.

Opening the file with MS Excel will not report any error. I'm not familiar with MS-XLSB spec, but I fully understand your concern on this. I'm still trying to understand how an xlsb can be modified with Excel into such a state. I'll share once I've found out the reproducing steps or got files that I'm allowed to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants