win32com: how to tell if an excel cell is empty

Harold Howe hhowe at gowebway.com
Mon Oct 30 23:17:22 EST 2000


I am writing a python script to parse an excel file and move the data
into a database. In one section of the script, I want to test a
particular cell to see if it is empty. How do I do this?

I have tried these combinations, but none work. I thought the comparison
to None was the way to go <shrug>: 

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"

How do I test the return from Cells for an empty value? Is there a
constant that I compare it with (win32com.Empty) or some such thing? I
saw a reference to a VarType function in a VB group, but I don't think
that VarType is applicable in python.

Thanks in advance. If there is a better group for posting win32 specific
python questions, please let me know.

Harold Howe
http://www.bcbdev.com



More information about the Python-list mailing list