Excel is a number or possibly some text like an asterisk. Each member
of the list is a com object (I think) and I'm converting them to
integers (or to None if not numberic) but my method seems very silly.
Is this the best way to go about it?
It does exactly what it should, but it seems like a lot of extra BS to
convert my object to a string to a float to a rounded integer! Don't
laugh. I'm new at this!
THE SCRIPT:----------------------------------
import win32com.client
xlApp = win32com.client .Dispatch("Exce l.Application")
f = r"C:\py\Traffic Volumes\xlTestD ocs\3125113A.xl s"
xlApp.Visible = 0
xlApp.Workbooks .Open(f)
list = xlApp.ActiveWor kbook.ActiveShe et.Range("Q13:Q 36")
print list
print "\n"
def comObjToInteger (myObj):
try:
s = str(myObj)
fl = float(s)
integer = int(round(fl))
return integer
except:
return None
for i in list:
print comObjToInteger (i)
xlApp.ActiveWor kbook.Close(Sav eChanges=0)
xlApp.Quit()
del xlApp #clean up
----------------------------------------------
THE RESULT:--------------------
the list:
((4.79999999999 99998,), (u'*',), (2.0,), (1.600000000000 0001,),
(5.599999999999 9996,), (19.39999999999 9999,), (25.0,),
(38.79999999999 9997,), (32.79999999999 9997,), (21.0,), (24.0,),
(17.39999999999 9999,), (22.80000000000 0001,), (22.60000000000 0001,),
(33.79999999999 9997,), (35.39999999999 9999,), (29.19999999999 9999,),
(35.39999999999 9999,), (32.20000000000 0003,), (26.0,),
(24.39999999999 9999,), (22.80000000000 0001,), (14.0,), (11.6,))
my converted values:
5
None
2
2
6
19
25
39
33
21
24
17
23
23
34
35
29
35
32
26
24
23
14
12
----------------------------------