Make a system call to calculate a spreadsheet cell value

2

Is it possible for me to make a system call in order to calculate a cell value in LibreOffice Calc?

To clarify, can I set a cell's formula to something like this:

=B3*C4-system("/my/amazing/script B3 C5")

where the contents of cells B3 and C5 would be sent to /my/amazing/script as arguments?

Joseph R.

Posted 2013-08-18T16:19:49.333

Reputation: 474

Answers

1

AFAIK you can't call external programs from inside a Calc formula directly, but you can define a User-defined function as a "wrapper". This function may use the Shell command to call an external program. This way, you can make a system call "indirectly".

tohuwawohu

Posted 2013-08-18T16:19:49.333

Reputation: 8 627

This makes Calc immune to this CSV exploit

– Dan Dascalescu – 2018-01-11T02:35:02.533

I tried that on Linux but it didn't work. Function VOL(a, b, c) VOL = Shell("/usr/bin/gnome-calculator", 1, a+b+c, false) End Function, then =VOL(1,2,3) produced '0' and didn't run the calculator. Replacing 1 with 4 or false with true didn't help. – Dan Dascalescu – 2018-01-11T02:50:32.377

@DanDascalescu: Generally, it seems that the SHELL() command doesn't recognize STDOUT or the exit code of the executed command. To handle this, you may use the clipboard, as described in this answer. Regarding your example: try Shell("/usr/bin/gnome-calculator", 1, "-e " + a, false), with a as String = "1+2+3". This should open the calculator with the equation 1+2+3 ready to calculate.

– tohuwawohu – 2018-01-11T08:45:17.837