8. Gnumeric

This page provides a guide on how to setup and use Gnumeric for the IAC protocol.

Warning

Gnumeric needs to have the Python plugin loader enabled for it to function properly. Please see the instructions for more details.

8.1. Instructions

  1. Install Gnumeric. Make sure that Gnumeric is installed and works with Python by typing import Gnm in the Python interpreter. If it doesn’t raise an ImportError then it works.
  2. Enable the Python plugin loader in Gnumeric by going to Tools > Plug-ins... -> Plugin List and selecting it from the checkbox list.
  3. Make sure that Gnumeric is enabled in the interfaces.py file. You can access Gnumeric using the gnumeric scope name.
  4. Play with the interpreter to learn how the functionality works. Then use the server to create automation scripts! See the server module for a sample automation shell script.

If you wish to contribute to improving Gnumeric’s functionality, view the Gnumeric plugin documentation for Python or discover it’s properties using Python’s object introspection on Gnumeric’s module gi.repository.

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.

8.2. Example

Here is an example Hello, World! shell script. Run the server (iacs) and try this script:

#!/usr/bin/env bash
# Netcat: -u is for UDP, -c closes the connection on EOF

PORT=14733
if [[ $# -eq 3 ]]; then
    echo -e "gnumeric -> doc = new_document(1)\n" | nc -uc localhost $PORT
    echo -e "gnumeric -> sheet = doc.get_sheet(0)\n" | nc -uc localhost $PORT
    echo -e "gnumeric -> cell = sheet.fetch_cell('$1')\n" | nc -uc localhost $PORT
    echo -e "gnumeric -> cell.set_text('$2')\n" | nc -uc localhost $PORT
    echo -e "gnumeric -> 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:

gnumeric -> doc = new_document(1)
gnumeric -> sheet = doc.get_sheet(0)
gnumeric -> cell = sheet.fetch_cell('A1')
gnumeric -> cell.set_text('Hello, World!')
gnumeric -> doc.save_as('./hello.gnumeric')

And then run it as something like iaci < hello-gnumeric.txt (assuming it’s saved as that name).

8.3. Commands

gnumeric.new_document(number_of_sheets)
Example usage:

gnumeric -> doc = new_document(1)

Parameters:number_of_sheets (int) – The number of sheets to create in the document.
Returns:A workbook object.
Noindex:
document.get_sheet(sheet_index)
Example usage:

gnumeric -> sheet = doc.get_sheet(0)

Parameters:sheet_index (int) – The index of the sheet to access.
Returns:A sheet object.
Noindex:
sheet.fetch_cell(cell_range)
Example usage:

gnumeric -> cell = sheet.fetch_cell(‘A1’)

Parameters:cell_range (str) – The cell to be fetched.
Returns:A cell object.
Noindex:
cell.set_text(string)
Example usage:

gnumeric -> cell.set_text(“Hello, World!”)

Parameters:string (str) – A string to set the cell contents to.
Returns:True on success, False otherwise.
Noindex:
cell.get_text()
Example usage:

gnumeric -> cell.get_text()

Returns:The cell’s text.
Noindex:
workbook.save_as(path)
Example usage:

gnumeric -> doc.save_as(‘/home/gyeh/hello.gnumeric’)

Parameters:path (str) – The path to save the workbook to (must end with .gnumeric)
Returns:True on success, False otherwise.
Noindex:

Table Of Contents

Previous topic

7. IAC protocol plugin implementation

Next topic

9. LibreOffice Writer

This Page