This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

python win32com fail?

Hi guys,

I have a very weard case with a python action. The case is that I have to convert from xls excel file to xslx. The xls is not pure xls, it has rubbish and after trying to use openpyxl and other, it works fine with win32com, in fact this is the native API to use MS office tools.

The script has been succesfully tested in my PC with Pycharmm and at RPA server trough CMD using pyhon.exe at C:\Program Files\Micro Focus\Robotic Process Automation\python\python-3.8.5>

(installation folder)

This script is the following

import win32com.client as win32

def execute(ruta, fichero):

excel = win32.gencache.EnsureDispatch('Excel.Application')
fname = ruta + fichero
excel.Visible = False

wb_origen = excel.Workbooks.Open(ruta + fichero)
wb_origen.SaveAs(fname + 'x', FileFormat=51)
return {"nuevoFichero": fname + 'x'}

Once I try to execute on designer defining a flow in which parameters I set ruta (path) and fichero (file), it doesn't works, it produce a message like:

Failed to execute user script: line 75
Microsoft Excel cannot access the file
There may be several reasons: \ n \ n • The file name or path does not exist. \ N • The file is being used by another program. \ N • The workbook you are trying to save has the same name as another workbook that is open in these moments.

path and folder exists, and there is nor another program using it neither same file existing.

I guess that exists and incompatibility between RPA and win32com library, or I think that the way of execute python scripts from designer is different than execute a ptyhon.exe from shell.

Nowadays I'm using an RPA activity to open excel and save as, but is not stable and most of the time windows excel task, crahs or hang, so I'm not confidento on it, that's the reason I'm looking for a simple process to convert the file, as simple as it can be.

Any idea?

Note: attached screenshots