Reputation: 39
I tried to convert .xls to .xlsx
this is my code:
import os
address = os.getcwd()
import win32com.client as win32
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!!')
Then I got error:
Traceback (most recent call last):
File "c:\Users\shenshuaic\Desktop\SFP Program\win32test.py", line 10, in <module>
import win32com.client as win32
File "C:\Users\shenshuaic\AppData\Local\Continuum\anaconda3\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: The specified procedure could not be found.
I have already reinstall pywin32. It is still happen
Upvotes: 2
Views: 9502
Reputation: 91
I am using Spyder and I initially tried:
conda install pywin32
import win32com.client
But kept getting an error. So I tried:
conda install -c conda-forge pywin32
and then
import win32com.client
It works perfectly.
Upvotes: 0
Reputation: 322
The traceback indicates that the problem actually occurs when importing win32api. I had the same issue while trying to import win32api directly (rather than importing win32.client). This answer helped: https://stackoverflow.com/a/60611014/7520085
(...) After copied the two files from Lib\site-packages\pywin32_system32 to C:\Windows\System32, it works. (...) The two files are pythoncom38.dll and pywintypes38.dll.
Upvotes: 3
Reputation: 11
This error comes from DLLs from pywin32 not being put in the right place during the installation process.
Running this in the anaconda prompt helped me:
conda install -c conda-forge pywin32
Upvotes: 1