首页 > 编程知识 正文

python处理excel教程,python将结果写入文件

时间:2023-05-03 15:51:35 阅读:146529 作者:1177

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 ) ) )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。