Reputation: 154
I'm trying to reference multiple cells in a function using openpyxl, like is shown in this code:
from openpyxl.workbook import Workbook
import os
wb = Workbook()
ws = wb.get_active_sheet()
ws.cell("A1").value = 1
ws.cell("A2").value = 2
ws.cell("A3").value = "=SUM(A1;A2)"
wb.save(os.path.join(os.getcwd(), "test.xlsx"))
When opening the output file with OpenOffice, the formula for cell A3 changes to =SUM(A1|A2)
and the cell displays an error.
Why did the ";" character change and how can I solve this?
Upvotes: 0
Views: 1945
Reputation: 8421
This: SUM(A1;A2)
is not a valid Excel formula.
Now, with certain language settings (which use a comma as the decimal separator), a semicolon is used in place of a comma in formulae, but openpyxl
explicitly does not support this (emphasis mine):
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 I imagine that it is replacing the illegal character (with something equally illegal). If you replace your ;
with a :
, you should be OK
Upvotes: 3