Error writing a formula with editpyxl in xlsx

29 Views Asked by At

I am unable to write a formula with editpyxl xlsx, with the following code:

import editpyxl
wb = editpyxl.Workbook()
wb.open("test.xlsx")
wb.active = wb['Sheet1']
ws= wb['Sheet1']
ws.cell(row=3, column=3).formula = "=SUM(A2:A6)"
wb.save()
  • When the cell "C3" is empty I get the following error:

test.xlsx test 1 content:

test.xlsx test 1 content

Traceback (most recent call last):
  File "C:\Users\username\Desktop\test.py", line 5, in <module>
    ws.cell(row=3, column=3).formula = "=SUM(A2:A6)"
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Local\Programs\Python\Python312\Lib\site-packages\editpyxl\worksheet.py", line 64, in cell
    raise IndexError('Cell {0} on {1} does not exist'.format(coordinate, self.name))
IndexError: Cell C3 on Sheet1 does not exist
  • When the cell "C3" contains a dummy value I get the next error:

test.xlsx test 2 content:

test.xlsx test 2 content

Traceback (most recent call last):
  File "C:\Users\username\Desktop\test.py", line 5, in <module>
    ws.cell(row=3, column=3).formula = "=SUM(A2:A6)"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Local\Programs\Python\Python312\Lib\site-packages\editpyxl\cell.py",     line 81, in formula
    raise AttributeError('Unable to update cell {0} to {1} - check cell type.'.format(self.name, v))
AttributeError: Unable to update cell C3 to =SUM(A2:A6) - check cell type.

I am using editpyxl 0.1.10

Thank you in advance for your help and time!

I would like to be able to write a formula in an xlsx file with editpyxl

0

There are 0 best solutions below