I haven’t used it myself, but I believe Simple Emacs Spreadsheets lets you write formulas in emacs lisp.
https://www.gnu.org/software/emacs/manual/html_node/ses/inde...
https://www.gnu.org/software/emacs/manual/html_node/ses/inde...
https://orgmode.org/worg/org-tutorials/org-spreadsheet-lisp-...
I've only dabbled with it, I am guessing for anything really substantial it would be quite slow compared to e.g. Excel.