win32com: how to tell if an excel cell is empty

Robin Becker robin at jessikat.fsnet.co.uk
Tue Oct 31 04:04:49 EST 2000


In article <39FE48C9.B4F00766 at gowebway.com>, Harold Howe
<hhowe at gowebway.com> writes
...
>import win32com.client
>excel = win32com.client.Dispatch("Excel.Application")
>wkbook = excel.Workbooks.Open('foo.xls')
>sheet = wkbook.Sheets("Sheet1")
>
>cell = sheet.Cells(1,1)
>
>if(cell == None):
>  print "empty"
>
>if(cell == 0):
>  print "empty"
>
>if(cell == "None"):
>  print "empty"
>
...
I would try sheet.Cells(1,1).Value and then test against 

None or ''.

ie
   v = sheet.Cells91,1).Value
   if v is None or str(v)=='': print 'Empty'

of course if you are reading a numeric array then perhaps any blank
string cell should be regarded as zero or some other default.
-- 
Robin Becker



More information about the Python-list mailing list