![](/img/trans.png)
[英]Write to multiple rows in excel sheet using pandas xlsxwriter
[英]Write multiple formulas to excel sheet with xlsxwriter in while loop
我正在嘗試使用帶有 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)
但是,如果我在調試中打印字符串並將 output 粘貼到調試控制台中,它會起作用並返回 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)
profiledatasheet.write_formula(
f'F{formularowcount}',
f'=IF(E{formularowcount}=MIN($E$2:$E${rowcount}),E{formularowcount},"")'
)
對於 python 2 類似
profiledatasheet.write_formula(
'F{0}'.format(formularowcount),
'=IF(E{0}=MIN($E$2:$E${1}),E{0},"")'.format(formularowcount, rowcount)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.