Hello to everybody!
I'm new in Python ... and have some problem with reading Excel...
no matter that I've set format in Excel Text (for all my available data) - it get float value from it...
Ok: here is the code:
<code>
import xlrd

book=xlrd.open_workbook("C:/Py/aaa.xls")
sh=book.sheet_by_index(0)

print sh.cell_value(RowN,CellN)

# it prints 1.0
</code>

Can somebody give me good suggestion ?
Thanks
Slava

Recommended Answers

All 3 Replies

Hello to everybody!
I'm new in Python ... and have some problem with reading Excel...
no matter that I've set format in Excel Text (for all my available data) - it get float value from it...
Ok: here is the code:

import xlrd

book=xlrd.open_workbook("C:/Py/aaa.xls")
sh=book.sheet_by_index(0)

print sh.cell_value(RowN,CellN)

# it prints     1.0

Can somebody give me good suggestion ?
Thanks
Slava

Forgot to say: it not problem to use int(...), the problem - I really don't know what will be data in excel cel: string either integer or float ....

hi,
I think that the float indicates the type of value. If I'm correct 0 is int and 1 is text
Anyway instead of that try this:

row_values(rowx, start_colx=0, end_colx=None)
col_values(colx, start_rowx=0, end_rowx=None)

each of them returns a sequence of values found in the cells belonging to a row/column.
the arguments are in order: (row/col to analyze, start col/row, end col/row) last two arguments are optional
when you have the list you can simply get the value you need from that.
see this

import xlrd
book = xlrd.open_workbook("C:\Python25\Test.xls")
sheet = book.sheet_by_index(0)
column = sheet.col_values(0, start_colx=0, end_colx=None)
row = sheet.col_values(2, start_rowx=0, end_rowx=1)
print column
print row
print column[2]
print row[:]

Let me know if this helps.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.