This page provides a guide on how to setup and use LibreOffice Calc for the IAC protocol.
Warning
LibreOffice needs to have the UNO bridge running for it to function properly. Please see the instructions for more details.
If you wish to contribute to LibreOffice Calc, try playing around with Python’s library imports for LibreOffice Calc. But the best way is probably to view the UNO API documentation online, available from both LibreOffice and OpenOffice, which are essentially identical APIs. If the functionality is written in Java or another language, please try to change the logic to Python. The same namespace and class names are typically used, so this isn’t usually difficult to do.
Then, clone the project repository from the project’s GitHub page, add your modified application, and submit a pull request to be reviewed. If your additions to the application follow the protocol convention and it doesn’t contain any obvious errors, it will be accepted! See IAC protocol plugin implementation for more details.
Here is a sample demonstrating LibreOffice Calc’s functionality. First, run the UNO bridge:
libreoffice "--accept=socket,host=localhost,port=18100;urp;StarOffice.ServiceManager" --norestore --nofirststartwizard --nologo --calc
Run the server (iacs) and then run the following Hello, World! shell script:
#!/usr/bin/env bash
# Netcat: -u is for UDP, -c closes the connection on EOF
PORT=14733
if [[ $# -eq 3 ]]; then
echo -e "localc -> doc = new_document()\n" | nc -uc localhost $PORT
echo -e "localc -> sheet = doc.current_sheet()\n" | nc -uc localhost $PORT
echo -e "localc -> cell = sheet.fetch_cell($1)\n" | nc -uc localhost $PORT
echo -e "localc -> cell.set_text('$2')\n" | nc -uc localhost $PORT
echo -e "localc -> doc.save_as('$3')\n" | nc -uc localhost $PORT
else
echo "Usage: $0 [cell] [string] [path]"
fi
Or try the interpreter by directing the following as stdin:
localc -> doc = new_document()
localc -> sheet = doc.current_sheet()
localc -> cell = sheet.fetch_cell('A1')
localc -> cell.set_text('Hello, World!')
localc -> doc.save_as('/home/gyeh/hello.ods')
And then run it as something like iaci < hello-localc.txt (assuming it’s saved as that name).
localc -> doc = current_document()
Returns: | A document object. |
---|---|
Noindex: |
localc -> sheet = document.current_sheet()
Returns: | A spreadsheet object. |
---|---|
Noindex: |
localc -> doc = load_document(‘/home/gyeh/hello.ods’)
Parameters: | path (str) – The path where the document is (must end with .ods) |
---|---|
Returns: | A document object. |
Noindex: |
localc -> doc = new_document()
Returns: | A document object. |
---|---|
Noindex: |
localc -> doc.save_as(‘/home/gyeh/hello.ods’)
Parameters: | path (str) – The path to save the document to (must end with .ods) |
---|---|
Returns: | True on success, False otherwise. |
Noindex: |
localc -> sheet.fetch_cell(‘A1’)
Returns: | A cell object. |
---|---|
Noindex: |
localc -> cell.set_text(“Hello, World!”)
Parameters: | string (str) – A string to set the cell contents to. |
---|---|
Returns: | True on success, False otherwise. |
Noindex: |
localc -> cell.get_text()
Returns: | The cell’s text. |
---|---|
Noindex: |
localc -> cell.weight(‘bold’)
Returns: | True on success, False otherwise. |
---|---|
Noindex: |