import win32com.client
ExObj = win32com.client.Dispatch("Excel.Application")
ExObj.Visible = 1
wb = ExObj.Workbooks.Open('')
ws = wb.Worksheets[0]
ws.printout()
这将打开和Excel文件发送到打印机并打印出来,但随后产生以下错误:打印()类型错误布尔
Traceback (most recent call last):
File "U:/rmarshall/Work For Staff/ROB/_Python/__Python Projects Code/Time Sheet.py", line 26, in <module>
ws.printout()
TypeError: 'bool' object is not callable
如何避免这个错误?
如果一切按预期工作,只需在(TypeError)块之外的尝试中将其包装并忽略它。 –
'printout'在这里是一个布尔值,而不是一个方法,它出现了。 –
@IonutHulub:对,只是压制你不喜欢的所有异常。把头伸进沙子里,呃? –