write_formula(row, col, formula[, cell_formula[, value]])
向工作表单元格写入公式。
参数:
worksheet.write_formula(0, 0, '=B3 + B4')
worksheet.write_formula(1, 0, '=SIN(PI()/4)')
worksheet.write_formula(2, 0, '=SUM(B1:B5)')
worksheet.write_formula('A4', '=IF(A3>1,"Yes", "No")')
worksheet.write_formula('A5', '=AVERAGE(1, 2, 3, 4)')
worksheet.write_formula('A6', '=DATEVALUE("1-Jan-2013")')
worksheet.write_formula('A7', '{=SUM(A1:B1*A2:B2)}')
cell_format参数用于向单元格应用格式。这个参数是可选,但在启用时,它必须是一个有效的格式对象。
如有需要,使用可选的value参数指定公式的计算结果也是可行的。有时在无法使用公式计算结果的非Excel应用上运行时用到它:
worksheet.write('A1', '=2+2', num_format, 4)
无论Excel的区域或语言版本是什么, Excel都以US风格存储公式:
worksheet.write_formula('A1', '=SUM(1, 2, 3)') # 正常运行
worksheet.write_formula('A2', '=SOMME(1, 2, 3)') # 法语,报错。
Examples of these functions are ACOT , CHISQ.DIST.RT , CONFIDENCE.NORM , STDEV.S and WORKDAY.INTL . In XlsxWriter these require a prefix:
worksheet.write_formula('A1', '=_xlfn.STDEV.S(B1:B10)')