作者:guoqiuping98_376 | 来源:互联网 | 2024-12-18 11:12
iamintheprocessofbrainstorminghowtobesttacklethebelowproblem.anyinputisgreatlyappreciated。
样例excel sheet columns :
columna
orange
pear
iwantexceltotellmewhetheritemsincolumnaandbmatchormismatchanddisplayresultsincolumnc.theformulaienterincolumncwouldbe=if ()
On excel,iwouldjustdragtheformulatotherestofthecellsincolumnctoapplytheformulatothemandtheresultwouldbe 3360
columna/p apple
orange
pear
oautomatethisusingapythonscript,I三向:
导入openpyxl
WB=openpyxl.load _ workbook (' test.xlsx ' )。
sheet=WB.get _ sheet _ by _ name (sheet1) )。
forcellobjinsheet.columns [2] :
cellobj.value='=if($a$1=$b$1,' Match ',' Mismatch ' ) )
WB.save(test.xlsx ) )。
thiswrotetheformulatoallcellsincolumnc,howevertheformulaonlyreferencedcella1andlcdhb,soresultinallcelllsincolumnc=match。
columna/p apple
orange
pear
How would you handle this?
youprobablywanttomakethecreationoftheformuladynamicsoeachrowofctakesfromthecorrespondingrowsofaandb 3360
for i,cellobjinenumerate (sheet.columns [2],1 ) :
cell obj.value='=if ($ a $ {0}=$ b $ {0}、' Match '、' Mismatch ' ).format(i ) I ) ) )