我试图使用Python 2.7中的xlsxwriter
在一个工作表的多个单元格中填充公式。我需要将公式作为包含单引号和双引号的字符串传入,如下所示:
'F2','=IF(E2=MIN($E$2:$E$545),E2,"")'
,其中行值存储在脚本中的变量中为formularowcount
和rowcount
我得到了这个异常:AttributeError: 'NoneType' object has no attribute 'group'
守则:
while rowcount > formularowcount:
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)
但是,如果我在debug中打印字符串并将输出粘贴到debug控制台,它将工作并返回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
我的语法有什么问题吗
试试这个(如果你使用3)
对于Python2,类似于
)
相关问题 更多 >
编程相关推荐