ws.Buttons
是一种方法,在调用时返回一个COMObject。所以你需要在它后面直接加括号。
from win32com.client import DispatchEx, Dispatch
excel = Dispatch('Excel.Application')
wb = excel.Workbooks.Open('some/path/')
ws = wb.Worksheets.Add()
# Show the difference between `ws.Buttons` and `ws.Buttons()`
print(type(ws.Buttons))
print(type(ws.Buttons()))
# Add button to worksheet
ws.Buttons().Add(786, 323.25, 109.5, 29.25)