LibreOffice Calc – How to Recalculate Using Terminal Command

command linelibreoffice

https://help.libreoffice.org/Calc/Recalculate
The title said it all. I have a Excel file with a lot of RANDBETWEEN() function. I wonder if I can regenerate the number without actually opening Libreoffice but using the terminal command?

Thanks in advance, guys.

Best Answer

RANDBETWEEN will recalculate automatically when the file is open. So create the following macro in My Macros, which simply saves and then quits.

Sub Recalculate()
   'ThisComponent.calculateAll()  ' Not needed
   ThisComponent.store()
   ThisComponent.close(True)
   dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
   dispatcher.executeDispatch(StarDesktop, ".uno:Quit", "", 0, Array())
End Sub

Then run the macro from the command line as described here: https://unix.stackexchange.com/questions/7295/how-to-invoke-an-openoffice-macro-from-the-linux-command-line.

However, despite the --invisible flag, the LibreOffice window will still appear. To keep it invisible, pass the filename as a parameter to the macro, and then call loadComponentFromUrl: https://superuser.com/questions/1135850/how-do-i-run-a-libreoffice-macro-from-the-command-line-without-the-gui.

Related Question