I am trying to autofill the excel formula =IFS(COUNTIF('PO'!$A$2:$A$11173,Q2)=0,"NO PO",COUNTIF('PO'!$A$2:$A$11173,Q2)>0,"HAVE PO")
in a column in an excel file with the following code in python.
#Pick the excel file I want to edit.
file_source =XXX.xlsx'
#The number of items in column "ELEMENT"
row_len = len(pd.read_excel(file_source,sheet_name='XCX', usecols=['ELEMENT']))
#load excel file
workbook = load_workbook(filename=file_source)
ws4 = workbook["XCX"]
#Autofill the formula
for g in range(2,row_len+2):
k="=IFS(COUNTIF('PO'!$A$2:$A$"+str(row_len+1)+",Q"+str(g)+')=0,"NO PO",'+"COUNTIF('PO'!$A$2:$A$"+str(row_len+1)+",Q"+str(g)+')>0,"HAVE PO")'
print(k)
ws4.cell(row=g,column=71).value=k
workbook.save(filename=file_source)
print(pd.read_excel(file_source,sheet_name='XCX', usecols=['Check']))
However, the output formulas shown in the output file are =@IFS(COUNTIF('PO'!$A$2:$A$11173,Q2)=0,"NO PO",COUNTIF('PO'!$A$2:$A$11173,Q2)>0,"HAVE PO")
which was added an @
between =
and IFS(COUNTIF('PO'!$A$2:$A$11173,Q2)=0,"NO PO",COUNTIF('PO'!$A$2:$A$11173,Q2)>0,"HAVE PO")
.
I had checked that the loop that I used to create formula wasn't wrong. Please help me finding out why the output foumula in excel is different from the one in python.