xlrd

Edwin.Madari at VerizonWireless.com Edwin.Madari at VerizonWireless.com
Mon Aug 4 09:08:40 EDT 2008


here is working code that will read & display  contents of all rows & columns in all the sheets, you need xlrd 0.6.1

import xlrd, os, sys

book = xlrd.open_workbook(sys.argv[1])
print "The number of worksheets is", book.nsheets
for shx in range(book.nsheets):
   sh = book.sheet_by_index(shx)
   print 'tab:%s rows:%s cols:%s ' % (sh.name, sh.nrows, sh.ncols)
   for rx in range(sh.nrows):
      for cx in range(sh.ncols):
         try:
            if sh.row_types(rx)[cx] and sh.row_values(rx)[cx]:
               print '%4s %s' % (xlrd.cellname(rx, cx), sh.row_values(rx)[cx])
         except:
            print xlrd.cellname(rx, cx), 'Exception - could not read'
   print

-----Original Message-----
From: python-list-bounces+edwin.madari=verizonwireless.com at python.org
[mailto:python-list-bounces+edwin.madari=verizonwireless.com at python.org]
On Behalf Of Gary Herron
Sent: Monday, August 04, 2008 5:01 AM
Cc: python-list at python.org
Subject: Re: xlrd


Yeats wrote:
> Hi,
>  
> Years ago i use xlrd to read data from excel and now I need again, but 
> i get strange result. The code is:
>  
> from xlrd import *
>  
> Planilha = open_workbook('C:\\Resultados.xls')
> Resultados = Planilha.sheet_by_name('Resultados')
> c = (Resultados.cell_value(2,2))
> print c
>  
> and the result is: 0, but the value in cell is : VERDADEIRO
>  
> What´s the problem

I've never used xlrd, but based on other packages for accessing spread 
sheets, here's one guess.

Cells can have numeric values or string values.  Your cell apparently 
has a string, but you are asking for a numeric value, so you get a 
zero.  Should you be asking for a string value?  (That's the way 
OpenOffice/python works if I remember correctly.)

Or are you accessing a different cell because you've confused 0-based / 
1-based indexing?

Or are you using old outdated versions of xlrd, Python or Excel?

Gary Herron



>  
> Thanks and sorry my bad english
> Yeats
>  
> ------------------------------------------------------------------------
>
> --
> http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.





More information about the Python-list mailing list