I'm reading an Excel sheet and printing the data returned from it. But when the data in the cells are float values, the output is printed as Long int. How do I get the float value as is from the Excel sheet using openpyxl (using openpyxl because it has good documentation). I know I could convert using float keyword but this doesn't work if used inside a loop which gives string as output as well.
Here is the sample excel data
A B C D
1 Device Manufacturer LMP Version No.of Devices
2 DUT CSR 4.0 1
3 REF1 Broadcom 4.0 3
code is:
import openpyxl
wb=openpyxl.load_workbook('/home/workspace/python/Book1.xlsx')
s = wb.get_sheet_by_name('Setup')
for j in s['A1':'D3']:
for cel in j:
print cel.coordinate,cel.value
print '-------------'
output is:
A1 Device
B1 Manufacturer
C1 LMP Version
D1 No. of Devices
-------------
A2 DUT
B2 CSR
C2 4
D2 1
-------------
A3 REF1
B3 Broadcom
C3 4
D3 3
The LMP version is Long int, how do I get the float value?


NUMBER. Which means it can't tell if your number is an integer or a float, and sees an exact value, and so OpenPyXl returns an integer. The solution is to callfloat.int, it's becauseopenpyxlhas implicitly converted it toint.