Python xlwings pywintypes.com_error

2022/06/19 22:49

Error

Xlwings pywintypes.com_error: (-2147352567, ‘Exception occurred.’, (0, None, None, None, 0, -2147352565), None)

Traceback (most recent call last):
  File "H:\PythonProject\name_data\read_name_from_excel.py", line 31, in <module>
    xw.Book(workbook_path).sheets[sheet_name].range("A" + str(row_num),
  File "C:\Users\Eddy\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\main.py", line 83, in __getitem__
    return self(key)
  File "C:\Users\Eddy\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\main.py", line 4314, in __call__
    return Sheet(impl=self.impl(name_or_index))
  File "C:\Users\Eddy\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\_xlwindows.py", line 617, in __call__
    return Sheet(xl=self.xl(name_or_index))
  File "C:\Users\Eddy\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\_xlwindows.py", line 160, in __call__
    v = self._inner(*args, **kwargs)
  File "C:\Users\Eddy\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x9.py", line 36625, in __call__
    ret = self._oleobj_.InvokeTypes(0, LCID, 2, (9, 0), ((12, 1),),Index
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)

Solution

If you got this error, the reason is probably du to the Excel path or sheet name is  not right. Just check your Excel path or sheet name.

Leave a Reply

Back to top