possible to run calc non-interactively?

I would like to invoke calc so that it runs non-interactively and does the following:

(1) Open the specified workbook.

(2) Modify the values of one or more cells.

(3) Recalculate cells whose values depend on values in cells modified in (2).

(4) Save and close the workbook.

Can this be done? If so, how?

Phillip M. Feldman

Home Page: http://phillipmfeldman.org

One approach is to run a macro stored in the document or in My Macros. Here is an example in Basic:

Sub ChangeSomeValues
    oDoc = ThisComponent
    oSheet = oDoc.getSheets().getByIndex(0)
    oCell = oSheet.GetCellRangeByName("A1")
    oCell.setValue(oCell.getValue()+1)
    oCell = oSheet.GetCellRangeByName("A2")
    oCell.setValue(42)
    oDoc.store()
    oDoc.close(True)
End Sub

Then call it like this.

soffice "change values noninteractively.ods" "vnd.sun.star.script:Standard.Module1.ChangeSomeValues?language=Basic&location=document"

The example document: change values noninteractively.ods

While this is not interactive, the window will still appear. To hide the window, see my answer at How do I run a LibreOffice macro from the command line without the GUI? - Super User.

Another approach is to use an external python script or a live python shell. To do this, start LibreOffice listening. A good tutorial is at Interface-oriented programming in OpenOffice / LibreOffice : automate your office tasks with Python Macros.