Data Extraction From Xls Using Xlrd In Python
Solution 1:
You can define the text as string,while appending data to the list in list1.append(str(sheets.cell(rows, col).value)) to remove [u' .The code will be:
from xlrd import open_workbook
xls=open_workbook('name.xls')
for sheets in xls.sheets():
list1=[]
for col in range(sheets.ncols):
for rows in range(sheets.nrows):
list1.append(str(sheets.cell(rows, col).value))
print(list1)
for i in list1:
print i
Solution 2:
Assuming you are using Python 2.x, the u
thing says that xlrd gives you unicode strings (what Excel strings really are). If you want to convert them in Python 2.7 strings, you have to encode them with the charset you use
Assuming you use latin1 (also knows as iso-8859-1 or (with minimal differences) windows-1252, you can transform your list of unicode strings in a list of latin1 strings that way :
strlist = [ elt.encode('latin1') for elt in list1 ]
or if you have only ASCII characters
strlist = [ str(elt) for elt in list1 ]
Solution 3:
I solved it by doing
str(variable_name)
Solution 4:
For practical matters, the u
in the beginning won't affect u. U can work with them as well unless you have some issues related to encoding it in different formats.
Post a Comment for "Data Extraction From Xls Using Xlrd In Python"