我需要用公式替换原始数据表(来自此表)中的几列。
我已经使用 Xlwings 包来执行此操作,并且它对其他公式成功,但不是这个特定的公式。
这些公式有效;
#column Y: Year 1-FA #Works perfectly
sheet_obj.range("Y2:Y"+str(max_row)).formula = f'=IF(NUMBERVALUE(C2)=1,CONCAT("Y1-",L2),L2)'
#column z: custom #Works perfectly
sheet_obj.range("Z2:Z"+str(max_row)).formula = f'=CONCAT(B2,"-",E2,"-",I2,"-",J2,"-",K2)'
以下内容返回错误;
#column P: New Out of PP #this is whwre the it shows error
sheet_obj.range("P2:P"+str(max_row)).formula = f'''=IFERROR(IF(OR(O2<>"",O2<>"NULL"),IF(OR(J2="Term 1",J2="Term 33"),O2+MIN(XLOOKUP(CONCAT(N2,C2,J2,H2),Subject_Map!$G:$G,Subject_Map!$H:$H,"",0),Raw(Merged)!S2),O2),O2),O2)'''
我要分配的公式是
'=IFERROR(IF(OR(O2<>"",O2<>"NULL"),IF(OR(J2="Term 1",J2="Term 33"),O2+MIN(XLOOKUP(CONCAT(N2,C2,J2,H2),Subject_Map!$G:$G,Subject_Map!$H:$H,"",0),Raw(Merged)!S2),O2),O2),O2)'
我认为问题在于工作表名称 Raw(Merged),您需要在其周围加上单引号,'Raw(Merged)'!S2:
sheet_obj.range("P2:P"+str(max_row)).formula.range("P2:P4").formula = '''=IFERROR(IF(OR(O2<>"",O2<>" NULL"),IF(OR(J2="学期 1",J2="学期 33"),O2+MIN(XLOOKUP(CONCAT(N2,C2,J2,H2),Subject_Map!$G:$G,Subject_Map! $H:$H,"",0),'原始(合并)'!S2),O2),O2),O2)'''