在 while 循环中使用 xlsxwriter 将多个公式写入 excel sheet
Write multiple formulas to excel sheet with xlsxwriter in while loop
我正在尝试使用 xlsxwriter
和 Python 2.7 在 sheet 的多个单元格中填充公式。我需要将公式作为包含单引号和双引号的字符串传递,如下所示:
'F2','=IF(E2=MIN($E:$E5),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:$E$"+str(rowcount)+"),E"+str(formularowcount)+",\"""\")'")
我尝试存储字符串本身并将其传入,但得到相同的异常:
formulavalue = "'F"+str(formularowcount)+"','=IF(E"+str(formularowcount)+"=MIN($E:$E$"+str(rowcount)+"),E"+str(formularowcount)+",\"""\")'"
profiledatasheet.write_formula(formulavalue)
但是,如果我在调试中打印出字符串并将输出粘贴到调试控制台,它就可以工作 returns 0:
print(formulavalue)
'F2','=IF(E2=MIN($E:$E5),E2,"")'
profiledatasheet.write_formula('F2','=IF(E2=MIN($E:$E5),E2,"")')
0
关于我的语法有什么问题有什么想法吗?
试试这个(如果你使用 3)
profiledatasheet.write_formula(
f'F{formularowcount}',
f'=IF(E{formularowcount}=MIN($E:$E${rowcount}),E{formularowcount},"")'
)
对于python 2 类似
profiledatasheet.write_formula(
'F{0}'.format(formularowcount),
'=IF(E{0}=MIN($E:$E),E{0},"")'.format(formularowcount, rowcount)
)
我正在尝试使用 xlsxwriter
和 Python 2.7 在 sheet 的多个单元格中填充公式。我需要将公式作为包含单引号和双引号的字符串传递,如下所示:
'F2','=IF(E2=MIN($E:$E5),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:$E$"+str(rowcount)+"),E"+str(formularowcount)+",\"""\")'")
我尝试存储字符串本身并将其传入,但得到相同的异常:
formulavalue = "'F"+str(formularowcount)+"','=IF(E"+str(formularowcount)+"=MIN($E:$E$"+str(rowcount)+"),E"+str(formularowcount)+",\"""\")'"
profiledatasheet.write_formula(formulavalue)
但是,如果我在调试中打印出字符串并将输出粘贴到调试控制台,它就可以工作 returns 0:
print(formulavalue)
'F2','=IF(E2=MIN($E:$E5),E2,"")'
profiledatasheet.write_formula('F2','=IF(E2=MIN($E:$E5),E2,"")')
0
关于我的语法有什么问题有什么想法吗?
试试这个(如果你使用 3)
profiledatasheet.write_formula(
f'F{formularowcount}',
f'=IF(E{formularowcount}=MIN($E:$E${rowcount}),E{formularowcount},"")'
)
对于python 2 类似
profiledatasheet.write_formula(
'F{0}'.format(formularowcount),
'=IF(E{0}=MIN($E:$E),E{0},"")'.format(formularowcount, rowcount)
)