Err:508 in formula written with Openpyxl

时间秒杀一切 提交于 2020-04-30 11:20:10

问题


I have this script:

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

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.

Any idea where is the mistake?


回答1:


Searching in https://openpyxl.readthedocs.io/en/stable/usage.html#using-formulae as @Charlie Clark suggested, it says:

Warning

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.`

so this line:

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

must be:

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


来源:https://stackoverflow.com/questions/56970851/err508-in-formula-written-with-openpyxl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!