-1

I am unable to get integer number as text from .xls file via xlrd. I have the following data in my cell:

20

and the cell type in Excel is "Text"

Also I have the following code to read this value:

some_value = sheet.cell(row, column).value.encode('utf8')

But it gives me

AttributeError: 'float' object has no attribute 'encode'

sheet.cell(row, column).ctype returns 1. According to the documentation, it means "a Unicode string"

What am I doing wrong? How can I fix it?

Thanks in advance.

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
  • Seems like it should work. You probably need to give us more information. (Less verbiage; more cut-and-paste from actual code, actual interactive sessions, and actual tracebacks.) – John Y May 09 '14 at 14:19
  • Works fine for me also, ctype returns 1 and the encoding works doing it as per your example. Only time I got an error was before I changed the cell type to Text. – Padraic Cunningham May 09 '14 at 16:07
  • Voted down for not writing what you ended up doing to fix your problem. – DrOnline Sep 27 '19 at 07:05

1 Answers1

1

Have you tried just

some_value = sheet.cell(row, column)

That's what I have in my code, anything that can be converted to int, float gets automatically converted. Others are left as strings.

user3203010
  • 261
  • 1
  • 8