2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python在excel中写入公式_Python Excel操作模块XlsxWriter之写入公式write_formula()

python在excel中写入公式_Python Excel操作模块XlsxWriter之写入公式write_formula()

时间:2021-02-22 12:01:55

相关推荐

python在excel中写入公式_Python Excel操作模块XlsxWriter之写入公式write_formula()

worksheet.write_formula()

write_formula(row, col, formula[, cell_formula[, value]])

向工作表单元格写入公式。

参数:

row(int) - 单元格所在的行(索引从0开始计数)。

col(int) - 单元格所在的列(索引从0开始计数)。

formula(string) - 写入单元格的公式。

cell_format(Format) - 可选的格式对象。

value - 可选的结果。公式计算后的值。

write_formula()方法根据

row和

column参数向指定的单元格写入公式或函数:

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-")')

也支持数组公式:

worksheet.write_formula('A7', '{=SUM(A1:B1*A2:B2)}')

参见下面的

write_array_formula()方法。

行-列和A1表示法都支持。

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)') # 法语,报错。

Excel and added functions which weren't defined in the original file specification. These functions are referred to as future functions.

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)')

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。