(original) (raw)
Hello, My name is Jiangyu, a Chinese man. You can call me Joe.
I learn Python for only one year. I think it's
a simple tools in my job some time.
But in my country, Python is a new tools for many people.
So If i have some
problems on it, I found it's difficult to look for the
answers$B!#(BSo I add the this mail list.
Now, I have a question about use win32com moudle for
MS-Excel.
Question: I want to insert a file into a Excel
sheet. But a exception occured in my
code.
Using VBA, I insert a file OK. And the processing in Python is equivalent
in VBA.
My environment: Python2.2.3 +
win32com + Win2000 Server + Excel(Office XP)
My Python code:
>>> from win32com.client import
Dispatch
>>> excel = Dispatch("Excel.Application")
>>> excel.Visible = 1
>>> excel.WorkBooks.Add()
>>> cursheet \= excel.ActiveWorkBook.ActiveSheet
>>> oleobjs = cursheet.OLEObjects()
>>> oleobjs.Add(Filename = r"c:\\temp.txt")
>>> excel = Dispatch("Excel.Application")
>>> excel.Visible = 1
>>> excel.WorkBooks.Add()
>>> cursheet \= excel.ActiveWorkBook.ActiveSheet
>>> oleobjs = cursheet.OLEObjects()
>>> oleobjs.Add(Filename = r"c:\\temp.txt")
My VBA code:
ActiveWorkbook.ActiveSheet.OLEObjects.Add
Filename:="c:\\temp.txt", Link:=False, DisplayAsIcon:=False
So, If you know how to do it. please answer me.
Thanks!
joe
2004/8/13