Reading floats from Excel using COM

A

Alagalah

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
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top