Automation Excel From Python getting "TypeError: 'unicode' object is not callable" on Range.Address
As per the Title, when I run the below code in Python 2.6 I get the below error on line:
print range.Addres开发者_如何学JAVAs(RowAbsolute=False, ColumnAbsolute=False)"
I know what the error means but the MSDN page (http://msdn.microsoft.com/en-us/library/aa174749(v=office.11).aspx) said this is valid and has an example in it. I have tried this in EXCEL VBA and it works.
TypeError: 'unicode' object is not callable
Any ideas?
Thanks.
Doanld
import win32com.client
xlApp = win32com.client.DispatchEx('Excel.Application')
xlApp.Visible = True
objWkb = xlApp.Workbooks.Add()
objSht = objWkb.Worksheets(1)
objSht.Cells(2,2).Value = '1'
objSht.Cells(2,3).Value = '2'
range = objSht.Cells(2,4)
range.Value = '=%s+%s' % (objSht.Cells(2,2).Address, objSht.Cells(2,3).Address)
range.AddComment('Test Comment')
print range.Address
print range.Address(RowAbsolute=False, ColumnAbsolute=False)
objWkb.Close(SaveChanges=False) #to avoid prompt
xlApp.Quit()
xlApp.Visible = 0 #must make Visible=0 before del self.excelapp or EXCEL.EXE remains in memory.
del xlApp
Range.Address
is a parameterized property. It provides a value when accessed like a property, but can be called like a method with parameters as well. PyWin32 does not support parameterized properties directly. It works around this by providing a GetXXXXX method for each property that supports parameters. Use:
range.GetAddress(RowAbsolute=False,ColumnAbsolute=False)
It can be used with or without keywords.
Use either:
range.GetAddress()
range.Address
To read the property.
精彩评论