我正在尝试使用xlsxwriter
在工作表的多个单元格中填充公式。该公式应如下所示:=IF(E2=MIN($E$2:$E$545),E2,"")
,行值存储在脚本中的变量中,分别为formularowcount
和rowcount
。
我收到此异常:AttributeError: 'NoneType' object has no attribute 'group'
。
代码:
while formularowcount < rowcount:
profiledatasheet.write_formula("'F"+str(formularowcount)+"','=IF(E"+str(formularowcount)+"=MIN($E$2:$E$"+str(rowcount)+"),E"+str(formularowcount)+",\"""\")'")
我已经尝试存储字符串本身并传递它,但是得到相同的异常:
formulavalue = "'F"+str(formularowcount)+"','=IF(E"+str(formularowcount)+"=MIN($E$2:$E$"+str(rowcount)+"),E"+str(formularowcount)+",\"""\")'"
profiledatasheet.write_formula(formulavalue)
但是,如果我在调试中打印出字符串并将输出粘贴到调试控制台,它将起作用并返回0:
print(formulavalue)
'F2','=IF(E2=MIN($E$2:$E$545),E2,"")'
profiledatasheet.write_formula('F2','=IF(E2=MIN($E$2:$E$545),E2,"")')
0
关于我的语法有什么问题的任何想法?
[试试看(如果您使用Python3)] >>
profiledatasheet.write_formula(
f'F{formularowcount}',
f'=IF(E{formularowcount}=MIN($E$2:$E${rowcount}),E{formularowcount},"")'
)