[python-win32] getting integer value for worksheet.Cells(row, col).Value

Vernon Cole vernondcole at gmail.com
Wed Nov 19 23:59:17 CET 2008


Solomon:
In what way did *int(worksheet.Cells(row, col).Value *not work? It seems
that it should have. (You should not do a "cast", you want a conversion). To
find out what's going on, try something like:

alpha = worksheet.Cells(row,col).Value
print 'Value was=', repr(alpha)

Perhaps there is something about the received string that will not convert.
For example, an empty string will give you a ValueError. You may have to use
something like:
try:
    val = int(alpha)
except ValueError:
   val = 0  # or do you want val = None ?
--
Vernon Cole

On Wed, Nov 19, 2008 at 1:55 AM, <Solomon.Zewdie.Altek at zf.com> wrote:

> Hi,
> the statement:  worksheet.Cells(row, col).Value returns a Value of type of
> Strings,
> Can anyone tell me how I can get an Integer value?
> Casting (int(worksheet.Cells(row, col).Value ) didn't work.
>
> Many Tnx!
>
> solomon
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081119/068aaf67/attachment.htm>


More information about the python-win32 mailing list