Форум сайта python.su
Если обрабативаются события Excel, выдает ошибку здесь:
workSheet.Range(“A2”).Value = “=A1+1” #pythoncom error: Python error invoking COM method.
workSheet.Range(“A3”).Formula = “=A1+1” #pythoncom error: Python error invoking COM method.
# -*- coding: CP1251 -*- import win32com.client, time, pythoncom class Events(): pass excelApp = win32com.client.DispatchWithEvents("Excel.Application", Events) excelApp.Visible = 1 workBook=excelApp.Workbooks.Add() workSheet=excelApp.ActiveWorkbook.ActiveSheet workSheet = win32com.client.DispatchWithEvents(workSheet, Events) workSheet.Range("A2").Value = "=A1+1" #pythoncom error: Python error invoking COM method. workSheet.Range("A3").Formula = "=A1+1" #pythoncom error: Python error invoking COM method. time.sleep(5) workBook.Close(False) excelApp.Quit() excelApp=workBook=workSheet=None pythoncom.CoUninitialize()
# -*- coding: CP1251 -*- import win32com.client, time, pythoncom excelApp = win32com.client.Dispatch("Excel.Application") excelApp.Visible = 1 workBook=excelApp.Workbooks.Add() workSheet=excelApp.ActiveWorkbook.ActiveSheet workSheet.Range("A2").Value = "=A1+1" #pythoncom error: Python error invoking COM method. workSheet.Range("A3").Formula = "=A1+1" #pythoncom error: Python error invoking COM method. time.sleep(5) workBook.Close(False) excelApp.Quit() excelApp=workBook=workSheet=None pythoncom.CoUninitialize()
Офлайн