Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to read data from excel as it is seen on desktop

I am working on an excel workbook. I am using python script for operating on the workbook. But there two issues:

1) There are some cells which have integer values. When I am reading that values and putting the read value into a report file (.txt), it is appending .0 with the number. Eg. if there is value 6, it is giving 6.0 when it is not supposed to do this. I have read that there is nothing as integer in excel. Still, I have 1000s of parameters and thus, I cant convert directly all of them to integer using some python function because that may convert values which are actually float also.

2) And when I am reading boolean TRUE and FALSE, it is giving me 1 and 0. I want to get whatever text I see in the excel workbook on my desktop. I don't want any conversions like that.

I am using xlrd for excel operations in python.
Please tell me what I should do to solve this problem?
Note: My excel sheet contains more than 100 sheets and I can't modify "true or false" with "1 and 0" etc

like image 383
Aakash Goyal Avatar asked Mar 07 '14 06:03

Aakash Goyal


People also ask

Why is Excel opening but not visible?

However, sometimes when you open a workbook, you see that it is open but you can't actually see it. This could be as a result of an intentional or accidental hiding of the workbook (as apposed to a sheet). Under the VIEW tab you will see buttons called Hide and Unhide.


1 Answers

for the boolean question you can test ctype:

for rx in range(ws.nrows):
        for cx in range(ws.ncols):
            print ws.cell(rx,cx).value, ws.cell(rx,cx).ctype

if the excel original cell is "TRUE" FALSE" the ctype value is 4

like image 198
Massimo Fuccillo Avatar answered Sep 28 '22 06:09

Massimo Fuccillo