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!
#!/usr/bin/python3
-- 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)
wb.Close()
excel.Application.Quit()
return
def operate_excel_bsh():
file2 = load_workbook(“C:\Users\yx\Documents\SAP\SAP GUI\BSH.xlsx”)
ws = file2.active
ws.delete_rows(idx=1,amount=9)
ws.delete_rows(idx=2)
ws.delete_cols(idx=1)
ws.delete_cols(idx=3)
ws.insert_cols(idx=5)
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
file2.save("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
else:
ws.delete_rows(2,count+1)
break
break
file2.save("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)
return
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 = file_bsh.active
now_time = str(datetime.datetime.now().strftime(‘%Y%m’))
now_time1 = str(datetime.datetime.now().strftime(‘%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
print(cell.value)
ws1.cell(row=i,column=j,value=cell.value)
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=11,value=cell.value)
ws1.cell(row=i,column=13,value=now_time1)
file_bshk.save("D:\\yxx\RPA\\Program\\FIN BSH auto invoice process\\BSH Invoice 2020(K).xlsx")
return