FAQ
Hi, I am using the Range function to return a tuple from Excel.

The data in the range (nREVENUE) in the excel file is 100.0, 101.0,
102.0, 103.0, 104.0

I can successfully iterate across the tuple and list, but when I try
and cast to a float to do some math, I get:

File "C:\Python25\lib\site-packages\win32com\client\__init__.py",
line 454, in __getattr__
raise AttributeError, "'%s' object has no attribute '%s'" % (repr
(self), attr)
AttributeError: '<win32com.gen_py.Microsoft Excel 12.0 Object
Library.Range instance at 0x37766608>' object has no attribute
'__float__'

**** CODE *****
import win32com.client
import os

excel=win32com.client.Dispatch("Excel.Application")
excel.Visible=0
excel.DisplayAlerts=False

#This is the file that contains the macro
xlsname=os.path.join(os.getcwd(),"nametest.xlsx")
nametest=excel.Workbooks.Open(xlsname)

revenue_list=excel.Range("nREVENUE")

revenue=[]
revenue.extend(revenue_list)

for i in range(len(revenue)):
rev=revenue[i]
print float(rev)

excel.Quit()
del excel

****************

I need to use COM as I will eventually need formula support, otherwise
I would use xlutils.

Any advice on how to cast the elements to a float would be greatly
appreciated!

Search Discussions

  • John Machin at Jul 15, 2009 at 1:05 am
    Alagalah <keith <at> nekotaku.com> writes:
    Hi, I am using the Range function to return a tuple from Excel.
    [big snip]

    Exact duplicate of question asked by "KB" on
    http://groups.google.com/group/python-excel ... see my answer there.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 15, '09 at 12:29a
activeJul 15, '09 at 1:05a
posts2
users2
websitepython.org

2 users in discussion

John Machin: 1 post Alagalah: 1 post

People

Translate

site design / logo © 2022 Grokbase