User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 426,811 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,894 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 606 | Replies: 3 | Solved
Reply
Join Date: Jun 2008
Posts: 6
Reputation: splakhin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
splakhin splakhin is offline Offline
Newbie Poster

Reading of Excel

  #1  
Jun 25th, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 6
Reputation: splakhin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
splakhin splakhin is offline Offline
Newbie Poster

Re: Reading of Excel

  #2  
Jun 25th, 2008
Originally Posted by splakhin View Post
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 ....
Reply With Quote  
Join Date: Jun 2008
Location: Milano, Italy
Posts: 16
Reputation: TheOneElectroni is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
TheOneElectroni's Avatar
TheOneElectroni TheOneElectroni is offline Offline
Newbie Poster

Re: Reading of Excel

  #3  
Jul 1st, 2008
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

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

Let me know if this helps.
Reply With Quote  
Join Date: Jun 2008
Posts: 6
Reputation: splakhin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
splakhin splakhin is offline Offline
Newbie Poster

Re: Reading of Excel

  #4  
Jul 17th, 2008
Thanks!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 8:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC