错误:用Openpyxl编写的公式中的508 [英] Err:508 in formula written with Openpyxl

查看:98
本文介绍了错误:用Openpyxl编写的公式中的508的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个脚本:

from openpyxl import Workbook

wb = Workbook()
ws = wb.active
ws['A1'] = 1 #any value
ws['B1'] = 0 #any value
ws['C1'] = 3 #any value
ws['D1'] = 0 #any value
ws['E1'] = "= IF(A1<>0;A1;1) * IF(B1<>0;B1;1) * IF(C1<>0;C1;1) * IF(D1<>0;D1;1)"
wb.save('error.xlsx')

当我使用LibreOffice Calc打开文件时,在E列中看到 Err:508 :

When I open the file with LibreOffice Calc, I see Err:508 in E column:

但是,如果我在命令行中编辑公式,而没有进行任何更改(即添加空格或删除任何字符并再次写相同的字符),则该公式有效.

However, if I edit the formula in the command line, without changing nothing (i.e. add an space or erase any character and write the same again) the formula works.

你知道哪里出了错吗?

推荐答案

警告

注意,对于函数,您必须使用英文名称,并且函数参数必须用逗号分隔,而不能使用其他标点符号(例如分号)分隔.

NB you must use the English name for a function and function arguments must be separated by commas and not other punctuation such as semi-colons.`

所以这行:

ws['E1'] = "= IF(A1<>0;A1;1) * IF(B1<>0;B1;1) * IF(C1<>0;C1;1) * IF(D1<>0;D1;1)"

必须是:

ws['E1'] = "= IF(A1<>0,A1,1) * IF(B1<>0,B1,1) * IF(C1<>0,C1,1) * IF(D1<>0,D1,1)"

这篇关于错误:用Openpyxl编写的公式中的508的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆