def gnm_init():
    global cc
    global ioc

    # Initialize Gnm itself
    Gnm.init()

    # create a stderr reporting context
    cc = Gnm.CmdContextStderr.new()

    # Load plugins
    Gnm.plugins_init(cc)

    # A context for io operations
    ioc = GOffice.IOContext.new(cc)

    return ()
#!/usr/bin/python
# -----------------------------------------------------------------------------

import gi
gi.require_version('Gnm', '1.12')
from gi.repository import Gnm
Gnm.init()

# A context for reporting errors to stderr
cc = Gnm.CmdContextStderr.new()

# Load plugins
Gnm.plugins_init(cc)

# -----------------------------------------------------------------------------

# Create a workbook with one sheet
wb = Gnm.Workbook.new_with_sheets(1)

# Get sheet.  Index starts at 0
sheet = wb.sheet_by_index(0)
print("Name: {}".format(sheet.props.name))
print("Number of columns: {}".format (sheet.props.columns))
print("Number of rows: {}".format (sheet.props.rows))

# Store values and expressions is some cells.  Coordinates are (col,row)
# both starting at 0.  (So what the gui sees as row 1 is 0 here.)
sheet.cell_set_value(0,0,Gnm.Value.new_int(10))
sheet.cell_set_value(0,1,Gnm.Value.new_float(101.25))
sheet.cell_set_text(0,2,"=A1+A2")
sheet.cell_set_text(0,3,"'01")
import gi
gi.require_version('Gnm', '1.12') 
gi.require_version('GOffice', '0.10') 
from gi.repository import Gnm
from gi.repository import GOffice
Gnm.init()

import sys
src_uri = GOffice.filename_to_uri (sys.argv[1])
dst_uri = GOffice.filename_to_uri (sys.argv[2])

# A context for reporting errors to stderr
cc = Gnm.CmdContextStderr.new()

# Load plugins
Gnm.plugins_init(cc)

# A context for io operations
ioc = GOffice.IOContext.new (cc)

# Read a file
wbv = Gnm.WorkbookView.new_from_uri (src_uri, None, ioc, None)
wb = wbv.props.workbook
print("Loaded {}".format(wb.props.uri))

# Save a file
fs = GOffice.FileSaver.for_file_name (dst_uri)
if wbv.save_as (fs, dst_uri, cc):
    print("Saved {}".format(wb.props.uri))
else:
    print("Failed to save to {}".format(dst_uri))