Моя Python версия 3.7.4,
моя версия pywin32 227
Я использовал Anaconda для написания своего кода
Я просто хочу конвертировать .xls файл в .xlsx это мой код:
import os
import win32com.client as win32
address = os.getcwd()
fname = address + "\\Bundles.xls"
fname2 = address + "\\searchresults.xls"
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel2 = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(fname)
wb5 = excel.Workbooks.Open(fname2)
wb.SaveAs(fname+"x", FileFormat = 51)
wb5.SaveAs(fname2+"x", FileFormat = 51) #FileFormat = 51 is for .xlsx extension
wb.Close()
wb5.Close() #FileFormat = 56 is for .xls extension
excel.Application.Quit()
excel2.Application.Quit()
print('File .xls convert .xlsx successful!!')
это моя ошибка:
PS C:\Users\shenshuaic\Desktop\SFP Program> &
C:/Users/shenshuaic/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/shenshuaic/Desktop/SFP
Program/win32test.py"
Traceback (most recent call last):
File "C:\Users\shenshuaic\AppData\Local\Continuum\anaconda3\lib\site-
packages\win32com\client\gencache.py", line 530, in EnsureDispatch
ti = disp._oleobj_.GetTypeInfo()
pywintypes.com_error: (-2147418111, 'Call was rejected by callee.', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/shenshuaic/Desktop/SFP Program/win32test.py", line 15, in <module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
File "C:\Users\shenshuaic\AppData\Local\Continuum\anaconda3\lib\site-
packages\win32com\client\gencache.py", line 541, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process - please run makepy manually for
this object")
TypeError: This COM object can not automate the makepy process - please run makepy manually for this
object