Below Python code is to read xls & xlsx file. Im facing a problem while reading an xlsx file. Error is "assert tvalue is not None"
--> workbook=xlrd.open_workbook("/home/perlzuser/sprint12/template.xlsx")
sheet=workbook.sheet_by_index(0)
data=[[sheet.cell_value(r,c) for c in range(sheet.ncols)]for r in range (sheet.nrows)]
print " ::",data
My error:::
/home/perlzuser/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/xlrd/xlsx.pyc in do_row(self, row_elem) 723 else: 724 bad_child_tag(child_tag) --> 725 assert tvalue is not None 726 self.sheet.put_cell(rowx, colx, XL_CELL_TEXT, tvalue, xf_index) 727 else:
AssertionError:
How to resolve this issue in python?
I have found a work around to resolve assertion error:
code:
import xlrd
from openpyxl import load_workbook
wb = load_workbook("/home/perlzuser/sprint12/template.xlsx")
wb.save("file_new.xlsx")
workbook=xlrd.open_workbook("file_name.xlsx")
sheet=workbook.sheet_by_index(0)
data=[[sheet.cell_value(r,c) for c in range(sheet.ncols)]for r in range (sheet.nrows)]
print "output:", data
Code Explanation:
Note: This copied file_new.xlsx can only be read by python code. It will be not in human readable format but your code will read it. You can use those data to store into DB or to write into other files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.