I’m trying to learn some python and I wanted for python to interact with excel using the win32 module. I found a basic example online on wiki here.
It won’t work however.
This is the error I get.
Traceback (most recent call last):
File "C:/Users/Greg/Desktop/python programming/excel2.py", line 8, in <module>
sheet.Range("A2").Value = str(Application.SIFilter(None, c.siObjectFilter))
NameError: name 'Application' is not defined
My question is what does that line DO EXACTLY and why am I getting an error?
sheet.Range(“A2”).Value = str(Application.SIFilter(None, c.siObjectFilter))
import win32com.client
from win32com.client import constants as c
excel = win32com.client.Dispatch("Excel.Application")
book = excel.Workbooks.Add()
sheet = book.Worksheets(1)
sheet.Range("A1").Value = "Hello World!"
sheet.Range("A2").Value = str(Application.SIFilter(None, c.siObjectFilter))
book.SaveAs("c:\simple_example.xls")
sheet = None
book = None
excel.Quit()
excel = None
Thanks sorry if I’m super noob….
The code you linked to looks like it’s pulled straight off of this blog. From the sound of it, you’re not trying to integrate with Softimage. You’ll want to just take that line out.
Also, if you’re working with Excel 2007 or later, you want to write to an
xlsxfile, because that’s whatExcel.Applicationis going to create for you.Here’s the same sample code modified with these changes.