Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xlrd cannot read xlsx file downloaded from email attachment

This is a very very strange issue. I have quite a large excel file (the contents of which I cannot discuss as it is sensitive data) that is a .xlsx and IS a valid excel file.

When I download it from my email and save it on my desktop and try to open the workbook using xlrd, xlrd throws an AssertionError and does not show me what went wrong.

When I open the file using my file browser, then save it (without making any changes), it works perfectly with xlrd.

Has anyone faced this issue before? I tried passing in various flags to the open_workbook function to no avail and I tried googling for the error. So far I haven't found anything.

The method I used was as follows


    file = open('bigexcelfile.xlsx')
    fileString = file.read()
    wb = open_workbook(file_contents=filestring)

Please help! The error is as follows


    Traceback (most recent call last):
      File "./varify/samples/resources.py", line 354, in post
        workbook = xlrd.open_workbook(file_contents=fileString)
      File "/home/vagrant/varify-env/lib/python2.7/site-packages/xlrd/__init__.py", line 416, in open_workbook
        ragged_rows=ragged_rows,
      File "/home/vagrant/varify-env/lib/python2.7/site-packages/xlrd/xlsx.py", line 791, in open_workbook_2007_xml
        x12sheet.process_stream(zflo, heading)
      File "/home/vagrant/varify-env/lib/python2.7/site-packages/xlrd/xlsx.py", line 528, in own_process_stream
        self_do_row(elem)
      File "/home/vagrant/varify-env/lib/python2.7/site-packages/xlrd/xlsx.py", line 722, in do_row
        assert tvalue is not None
    AssertionError

like image 442
user2654569 Avatar asked Apr 28 '14 16:04

user2654569


2 Answers

rename or Save as your Excel file as .xls instead of .xlsx Thank You

like image 119
Mohideen bin Mohammed Avatar answered Nov 15 '22 07:11

Mohideen bin Mohammed


Use pyopenxl, not xlrd, for this format: https://openpyxl.readthedocs.org/en/latest/

like image 28
Charles Duffy Avatar answered Nov 15 '22 06:11

Charles Duffy