Error invoking python method new problem

Hello all,i invoke python method in Uipath,but some methods invoke right and some wrong,here are my uipath settings and python codes,if you know the problem pls help me ,thank you in advance!


-- coding: utf-8 --

from openpyxl import load_workbook
import win32com.client as win32
import numpy as np
import pandas as pd
import datetime
#getting specified format of excel

The method change_excel_name invokes right,operate_excel_bsh invokes wrong.

def change_excel_name():
file1 = “C:\Users\yx\Documents\SAP\SAP GUI\BSH.xls”
excel = win32.gencache.EnsureDispatch(‘Excel.Application’)
wb = excel.Workbooks.Open(file1)
wb.SaveAs(file1 + “x”, FileFormat=51)

def operate_excel_bsh():
file2 = load_workbook(“C:\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx”)
ws =

ws.cell(1, 5, "New invoice")

x = 2
while x <= ws.max_row:
    ws.cell(x, 5, value=ws.cell(x, 6).value / ws.cell(x, 4).value)
    x += 1"C:\\Users\\yx\Documents\\SAP\\SAP GUI\\BSH.xlsx")

file_wk = load_workbook("D:\\yxx\RPA\\Program\\FIN BSH auto invoice process\\BSH Invoice 2020(K).xlsx")
wk = file_wk['202005']
max_cell = 1
for row in wk.iter_rows(min_col=1, max_col=1,min_row=2, max_row=""):
    for cell in row:
        if cell.value != None:
            max_cell = cell.value
count = 0
for row in ws.iter_rows(min_col=1, max_col=1, min_row=2, max_row=""):
    for cell in row:
        if cell.value != max_cell:
            count += 1
    break"C:\\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx")

bsh = pd.DataFrame(pd.read_excel('C:\\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx',sheet_name='BSH'))
bsh.sort_values(by='DocCa',ascending=False, inplace=True)
bsh.to_excel('C:\\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx',sheet_name='BSH', index=False)


def replace_excel_bshk():
file_bsh = load_workbook(“C:\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx”)
file_bshk = load_workbook(“D:\yxx\RPA\Program\FIN BSH auto invoice process\BSH Invoice 2020(K).xlsx”)
ws =
now_time = str(‘%Y%m’))
now_time1 = str(‘%m/%d/%Y’))
ws1 = file_bshk[now_time]

i = 1
j = 0
for row in ws.iter_rows(min_row=2, max_row="", min_col=1, max_col=6):
    i += 1
    for cell in row:
        j += 1
    j = 0
i = 1
for row in ws.iter_rows(min_row=2,max_row="",min_col=7,max_col=7):
    i += 1
    for cell in row:
        ws1.cell(row=i,column=13,value=now_time1)"D:\\yxx\RPA\\Program\\FIN BSH auto invoice process\\BSH Invoice 2020(K).xlsx")


Did you try in python? Is it working well?

also you need to take care of indentation also

Hope this helps


Yes,it works well in python.
But the method operate_excel_bsh invokes wrong in uipath.


Can you share your workflow with files, so that we can try


Invoke python (21.3 KB)
Pls have a look .


I only receive the uipath project file, i didn’t recevie any Python File, also in the path i see there are spaces, you can try to avoid spaces in the path by using ‘_’

Also attached the python script and required sample files

Thanks (1.1 KB)

Soory,here is my python code


I can’t replicate the problem, because i don’t have any excel file, but in python scope, check the path is correct also check is python is x86 or x64


Thank you anyway!

1 Like

Hi,I find a new information,
I create a new python Method,if i add “ws.delete_cols(idx=1,amount=9)”, the method invoke in uipath will be wrong,but if delete it ,then it’ll be right.Do you know why?

def test():
file2 = load_workbook(“C:\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx”)
ws =
#ws.delete_cols(idx=1,amount=9)“C:\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx”)