python win32com Dispatch, DispatchEx 无法打开(启动)excel pywintypes.com_error: (-2146959355, ‘服务器运行失败‘

2021/5/3 14:55:11

本文主要是介绍python win32com Dispatch, DispatchEx 无法打开(启动)excel pywintypes.com_error: (-2146959355, ‘服务器运行失败‘,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

最近换了个硬盘,重装电脑后,想用python打开excel,发现完全没反应,弹出以下错误信息:

asctime:        Sun, 02 May 2021 12:48:36 
bug_line:       line:509 
level:          ERROR 
message:        ERROR:(-2146959355, '服务器运行失败', None, None)
Traceback (most recent call last):
  File "D:\Python\Python38\lib\site-packages\win32com\client\dynamic.py", line 81, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, '操作无法使用', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:/发送房租软件/begin.py", line 503, in open_excel
    send_info_dict,fangzi_shuidian=open_excel.get_send_info()
  File "F:/发送房租软件/begin.py", line 184, in get_send_info
    month_info,shuidian_dict=self.get_all_info()  #获取所有租户所选月份对应的所有具体租金、水电量
  File "F:/发送房租软件/begin.py", line 177, in get_all_info
    self.creat_next_month(file)#提前创建当前月份/下个月的数据
  File "F:/发送房租软件/begin.py", line 215, in creat_next_month
    excel = Dispatch('excel.application')  # 创建Excel对象
  File "D:\Python\Python38\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "D:\Python\Python38\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "D:\Python\Python38\lib\site-packages\win32com\client\dynamic.py", line 83, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2146959355, '服务器运行失败', None, None)

期间下载了wps,以为是这个问题,不断重装excel跟wps,发现还是不行!!

百度了一番,基本是2个说法 

1.权限问题,python跟excel不是同一个权限------------------------------试来试去,都是用管理员授权了,还是不行

2.Excel.Application注册信息不对,所以pywin32无法调用

针对注册的说法,可以参考下这个老哥https://blog.csdn.net/l490134872/article/details/80250395

思路是对了,不过我在注册表查询时,发现有好几个Microsoft Excel Application,程序ID也是对得上的(注意在注册表搜索时,它的匹配方式是匹配!

所以得把它全改了才行!!!

太费劲了,所以我想,要不直接 通过注册表在dcom配置中重建excel应用程序 !!

参考这篇文章,具体内容我也贴上来了https://jingyan.baidu.com/article/14bd256e79a67dbb6d261299.html

  1. 打开记事本,把下列注册表代码复制到记事本中。

  2. Windows Registry Editor Version 5.00
    
    
    [HKEY_CLASSES_ROOT\AppID\{00020820-0000-0000-C000-000000000046}]
    
    @="Microsoft Office Excel 97-2003 工作表"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}]
    
    "IPersistStorageType"=dword:00000002
    
    @="Microsoft Office Excel 97-2003 工作表"
    
    "AppID"="{00020820-0000-0000-C000-000000000046}"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType\2]
    
    @="Worksheet"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType\3]
    
    @="Microsoft Office Excel 2003"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readable]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readable\Main]
    
    @="Biff8,ExcelWorksheet,ExcelML12,Biff12"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readwritable]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readwritable\Main]
    
    @="Biff8,ExcelML12,Biff12"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\DefaultFile]
    
    @="Biff8"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\0]
    
    @="3,1,32,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\1]
    
    @="2,1,16,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\2]
    
    @="1,1,1,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\3]
    
    @="NotesDocInfo,1,1,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\4]
    
    @="NoteshNote,-1,1,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DefaultExtension]
    
    @=".xls, Excel Workbook (*.xls)"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DefaultIcon]
    
    @="C:\\Windows\\Installer\\{90120000-0011-0000-0000-0000000FF1CE}\\xlicons.exe,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DocObject]
    
    @="16"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Implemented Categories]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Implemented Categories\{000C0118-0000-0000-C000-000000000046}]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\InprocHandler32]
    
    @="ole32.dll"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\InprocServer32]
    
    "Assembly"="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
    
    "Class"="Microsoft.Office.Interop.Excel.WorksheetClass"
    
    "RuntimeVersion"="v1.1.4322"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\InprocServer32\12.0.0.0]
    
    "Assembly"="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
    
    "Class"="Microsoft.Office.Interop.Excel.WorksheetClass"
    
    "RuntimeVersion"="v1.1.4322"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Insertable]
    
    @=""
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\LocalServer]
    
    @="C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
    
    "LocalServer"=hex(7):76,00,55,00,70,00,41,00,56,00,35,00,21,00,21,00,21,00,21,\
    
      00,21,00,21,00,21,00,21,00,21,00,4d,00,4b,00,4b,00,53,00,6b,00,45,00,58,00,\
    
      43,00,45,00,4c,00,46,00,69,00,6c,00,65,00,73,00,3e,00,74,00,57,00,7b,00,7e,\
    
      00,24,00,34,00,51,00,5d,00,63,00,40,00,49,00,49,00,3d,00,6c,00,32,00,78,00,\
    
      61,00,54,00,4f,00,35,00,00,00,00,00
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\LocalServer32]
    
    @="C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
    
    "LocalServer32"=hex(7):76,00,55,00,70,00,41,00,56,00,35,00,21,00,21,00,21,00,\
    
      21,00,21,00,21,00,21,00,21,00,21,00,4d,00,4b,00,4b,00,53,00,6b,00,45,00,58,\
    
      00,43,00,45,00,4c,00,46,00,69,00,6c,00,65,00,73,00,3e,00,74,00,57,00,7b,00,\
    
      7e,00,24,00,34,00,51,00,5d,00,63,00,40,00,49,00,49,00,3d,00,6c,00,32,00,78,\
    
      00,61,00,54,00,4f,00,35,00,00,00,00,00
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\MiscStatus]
    
    @="32"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\PersistentHandler]
    
    @="{98de59a0-d175-11cd-a7bd-00006b827d94}"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Printable]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\ProgID]
    
    @="Excel.Sheet.8"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Typelib]
    
    @="{00020813-0000-0000-C000-000000000046}"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Verb]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Verb\0]
    
    @="编辑(&E),0,2"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Verb\1]
    
    @="打开(&O),0,2"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Version]
    
    @="1.2"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}]
    
    "IPersistStorageType"=dword:00000002
    
    @="Microsoft Office Excel 97-2003 工作表"
    
    "AppID"="{00020820-0000-0000-C000-000000000046}"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType\2]
    
    @="Worksheet"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType\3]
    
    @="Microsoft Office Excel 2003"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readable]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readable\Main]
    
    @="Biff8,ExcelWorksheet,ExcelML12,Biff12"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readwritable]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readwritable\Main]
    
    @="Biff8,ExcelML12,Biff12"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\DefaultFile]
    
    @="Biff8"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\0]
    
    @="3,1,32,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\1]
    
    @="2,1,16,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\2]
    
    @="1,1,1,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\3]
    
    @="NotesDocInfo,1,1,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\4]
    
    @="NoteshNote,-1,1,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DefaultExtension]
    
    @=".xls, Excel Workbook (*.xls)"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DefaultIcon]
    
    @="C:\\Windows\\Installer\\{90120000-0011-0000-0000-0000000FF1CE}\\xlicons.exe,1"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\DocObject]
    
    @="16"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Implemented Categories]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Implemented Categories\{000C0118-0000-0000-C000-000000000046}]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\InprocHandler32]
    
    @="ole32.dll"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\InprocServer32]
    
    "Assembly"="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
    
    "Class"="Microsoft.Office.Interop.Excel.WorksheetClass"
    
    "RuntimeVersion"="v1.1.4322"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\InprocServer32\12.0.0.0]
    
    "Assembly"="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
    
    "Class"="Microsoft.Office.Interop.Excel.WorksheetClass"
    
    "RuntimeVersion"="v1.1.4322"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Insertable]
    
    @=""
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\LocalServer]
    
    @="C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
    
    "LocalServer"=hex(7):76,00,55,00,70,00,41,00,56,00,35,00,21,00,21,00,21,00,21,\
    
      00,21,00,21,00,21,00,21,00,21,00,4d,00,4b,00,4b,00,53,00,6b,00,45,00,58,00,\
    
      43,00,45,00,4c,00,46,00,69,00,6c,00,65,00,73,00,3e,00,74,00,57,00,7b,00,7e,\
    
      00,24,00,34,00,51,00,5d,00,63,00,40,00,49,00,49,00,3d,00,6c,00,32,00,78,00,\
    
      61,00,54,00,4f,00,35,00,00,00,00,00
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\LocalServer32]
    
    @="C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
    
    "LocalServer32"=hex(7):76,00,55,00,70,00,41,00,56,00,35,00,21,00,21,00,21,00,\
    
      21,00,21,00,21,00,21,00,21,00,21,00,4d,00,4b,00,4b,00,53,00,6b,00,45,00,58,\
    
      00,43,00,45,00,4c,00,46,00,69,00,6c,00,65,00,73,00,3e,00,74,00,57,00,7b,00,\
    
      7e,00,24,00,34,00,51,00,5d,00,63,00,40,00,49,00,49,00,3d,00,6c,00,32,00,78,\
    
      00,61,00,54,00,4f,00,35,00,00,00,00,00
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\MiscStatus]
    
    @="32"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\PersistentHandler]
    
    @="{98de59a0-d175-11cd-a7bd-00006b827d94}"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Printable]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\ProgID]
    
    @="Excel.Sheet.8"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Typelib]
    
    @="{00020813-0000-0000-C000-000000000046}"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Verb]
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Verb\0]
    
    @="编辑(&E),0,2"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Verb\1]
    
    @="打开(&O),0,2"
    
    
    [HKEY_CLASSES_ROOT\CLSID\{00020820-0000-0000-C000-000000000046}\Version]
    
    @="1.2"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{00020820-0000-0000-C000-000000000046}]
    
    @="Microsoft Office Excel 97-2003 工作表"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}]
    
    "IPersistStorageType"=dword:00000002
    
    @="Microsoft Office Excel 97-2003 工作表"
    
    "AppID"="{00020820-0000-0000-C000-000000000046}"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType\2]
    
    @="Worksheet"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\AuxUserType\3]
    
    @="Microsoft Office Excel 2003"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readable]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readable\Main]
    
    @="Biff8,ExcelWorksheet,ExcelML12,Biff12"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readwritable]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Conversion\Readwritable\Main]
    
    @="Biff8,ExcelML12,Biff12"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\DefaultFile]
    
    @="Biff8"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\0]
    
    @="3,1,32,1"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\1]
    
    @="2,1,16,1"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\2]
    
    @="1,1,1,1"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\3]
    
    @="NotesDocInfo,1,1,1"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DataFormats\GetSet\4]
    
    @="NoteshNote,-1,1,1"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DefaultExtension]
    
    @=".xls, Excel Workbook (*.xls)"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DefaultIcon]
    
    @="C:\\Windows\\Installer\\{90120000-0011-0000-0000-0000000FF1CE}\\xlicons.exe,1"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\DocObject]
    
    @="16"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Implemented Categories]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Implemented Categories\{000C0118-0000-0000-C000-000000000046}]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\InprocHandler32]
    
    @="ole32.dll"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\InprocServer32]
    
    "Assembly"="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
    
    "Class"="Microsoft.Office.Interop.Excel.WorksheetClass"
    
    "RuntimeVersion"="v1.1.4322"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\InprocServer32\12.0.0.0]
    
    "Assembly"="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
    
    "Class"="Microsoft.Office.Interop.Excel.WorksheetClass"
    
    "RuntimeVersion"="v1.1.4322"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Insertable]
    
    @=""
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\LocalServer]
    
    @="C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
    
    "LocalServer"=hex(7):76,00,55,00,70,00,41,00,56,00,35,00,21,00,21,00,21,00,21,\
    
      00,21,00,21,00,21,00,21,00,21,00,4d,00,4b,00,4b,00,53,00,6b,00,45,00,58,00,\
    
      43,00,45,00,4c,00,46,00,69,00,6c,00,65,00,73,00,3e,00,74,00,57,00,7b,00,7e,\
    
      00,24,00,34,00,51,00,5d,00,63,00,40,00,49,00,49,00,3d,00,6c,00,32,00,78,00,\
    
      61,00,54,00,4f,00,35,00,00,00,00,00
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\LocalServer32]
    
    @="C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
    
    "LocalServer32"=hex(7):76,00,55,00,70,00,41,00,56,00,35,00,21,00,21,00,21,00,\
    
      21,00,21,00,21,00,21,00,21,00,21,00,4d,00,4b,00,4b,00,53,00,6b,00,45,00,58,\
    
      00,43,00,45,00,4c,00,46,00,69,00,6c,00,65,00,73,00,3e,00,74,00,57,00,7b,00,\
    
      7e,00,24,00,34,00,51,00,5d,00,63,00,40,00,49,00,49,00,3d,00,6c,00,32,00,78,\
    
      00,61,00,54,00,4f,00,35,00,00,00,00,00
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\MiscStatus]
    
    @="32"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\PersistentHandler]
    
    @="{98de59a0-d175-11cd-a7bd-00006b827d94}"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Printable]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\ProgID]
    
    @="Excel.Sheet.8"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Typelib]
    
    @="{00020813-0000-0000-C000-000000000046}"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Verb]
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Verb\0]
    
    @="编辑(&E),0,2"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Verb\1]
    
    @="打开(&O),0,2"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00020820-0000-0000-C000-000000000046}\Version]
    
    @="1.2"
    

     

  3. 然后在记事本中,用替换把里面的EXCEL路径替换为你电脑对应的EXCEL所在路径,目前路径为C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE  如果一样就不用改动,直接另存为Excel应用.reg。注意文件扩展名为reg。

  4. 双击执行Excel应用.reg,导入注册表信息。

  5. 完成导入。重启电脑。

  6. 再进入dcomcnfg组件 DCOM配置,我安装的是32位的excel,所以实际改变路径的是

 

后面就可以成功启动excel了!!!



这篇关于python win32com Dispatch, DispatchEx 无法打开(启动)excel pywintypes.com_error: (-2146959355, ‘服务器运行失败‘的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程