### Install Gnumeric Debian Packages
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Installs the generated .deb packages for Gnumeric.
```bash
_$root_ `dpkg -i gnum*deb`
```
--------------------------------
### Install Gnumeric and Python Plugin (Debian)
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Installs Gnumeric, the Python plugin, and Python using apt-get on Debian systems.
```bash
_$root_ `apt-get install gnumeric gnumeric-python python`
```
--------------------------------
### Gnumeric Default Workbook XML Save Example
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/saving.txt
Example of the XML output when saving the default Gnumeric workbook.
```xml
Sheet 0
```
--------------------------------
### Build Gnumeric Dependencies (Debian)
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Installs build dependencies for Gnumeric on Debian systems using apt-get.
```bash
_$root_ `apt-get build-dep gnumeric`
```
--------------------------------
### Gnumeric Sheet XML Save Example
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/saving.txt
Example of the XML output when saving a Gnumeric sheet, including its name, dimensions, zoom, and column/row information.
```xml
Sheet 0
40
40
1.000000
-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*
```
--------------------------------
### Manipulate CellPos and Range Objects
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Examples of instantiating and inspecting Gnumeric CellPos and Range objects.
```python
# I wonder how to use CellPos (I've glanced at the source, but...)
>>> dir(Gnumeric.CellPos) # shows nothing useful
>>> Gnumeric.CellPos()
TypeError: CellPos() takes exactly 2 arguments (0 given)
>>> Gnumeric.CellPos("a1","a2")
TypeError: an integer is required. # Right.
>>> a=Gnumeric.CellPos(1,2) # It worked!
>>> a
# Yeah, I know...
>>> dir(a)
['get_tuple']
>>> a.get_tuple()
(1,2) # Cool. That's (col,row)
>>> r = Gnumeric.Range((1,2),(3,4))
TypeError: Range() argument 1 must be CellPos, not tuple
>>> r = Gnumeric.Range(a,a)
>>> r
>>> dir(r)
['get_tuple']
>>> r.get_tuple()
(3, 7, 3, 7)
```
--------------------------------
### Gnumeric: Aligning Positive Numbers with Parentheses
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/excel-format-doc.txt
Use an underscore followed by a character to create a space of that character's width in number formats. This example aligns positive numbers with negative numbers enclosed in parentheses.
```text
_( )
```
--------------------------------
### Creating New Gnumeric Values in Guile
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/guile-gnumeric.txt
Provides examples of functions used to create new Gnumeric value smobs from Scheme objects. These functions are essential for returning computed values from custom formulas.
```scheme
(value-new-empty scm)
```
```scheme
(value-new-bool scm)
```
```scheme
(value-new-int scm)
```
```scheme
(value-new-float scm)
```
```scheme
(value-new-string scm)
```
```scheme
(value-new-list scm)
```
```scheme
(value-new-array-list scm)
```
--------------------------------
### Execute Built-in Python Functions
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Example of invoking a Python-based function directly within a Gnumeric cell.
```text
=py_capwords("fred flintstone")
```
--------------------------------
### XML Representation of Workbook Attributes
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/pref-attributes.txt
Example of the XML structure used to store workbook attributes like scrollbar visibility.
```xml
Workbook::show_horizontal_scrollbar
4
FALSE
Workbook::show_vertical_scrollbar
4
FALSE
Workbook::show_notebook_tabs
4
FALSE
```
--------------------------------
### Gnumeric: Conditional Formatting for Numbers
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/excel-format-doc.txt
Set conditional values for a section by enclosing the condition in square brackets. Conditions can include <, >, =, >=, <=, or <>. This example displays entries greater than 1000 in blue.
```text
[>1000][Blue]#,##
```
--------------------------------
### Initialize Plugin Files
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Commands to create the necessary Python and XML files for a new plugin.
```bash
touch my-func.py
touch plugin.xml
```
--------------------------------
### Create a GnmStyle object
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/Styles.txt
Initialize a new style object, either empty or with default settings.
```C
GnmStyle *empty = gnm_style_new ();
GnmStyle *full_of_default_settings = gnm_style_new_default ().
```
--------------------------------
### Checkout and Build libgsf (CVS)
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Checks out and builds the libgsf library from CVS. Includes system-specific autogen.sh flags.
```bash
cvs co libgsf
```
```bash
cd libgsf
```
```bash
RedHat: `./autogen.sh`
```
```bash
Debian: `./autogen.sh --prefix=/usr --with-gconf-schema-file-dir=/etc/gconf/schemas`
```
```bash
`make`
```
```bash
_$root_ `make install`
```
--------------------------------
### Create Plugin Directory Structure
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Shell commands to initialize the required directory structure for a custom Gnumeric plugin.
```bash
mkdir ~/.gnumeric
mkdir ~/.gnumeric/
mkdir ~/.gnumeric//myfuncs/
cd ~/.gnumeric//myfuncs/
```
--------------------------------
### Enable Python Console via Shell
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Commands to set up the local plugin configuration for the Gnumeric Python console.
```bash
gnumeric --version
cd ~/.gnumeric/_$version_/plugins/
rsync -auvz /usr/lib/gnumeric/_$version_/plugins/python-loader ./
```
--------------------------------
### Remove Gnumeric Debian Packages
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Removes the generated .deb files after installation.
```bash
_$root_ `rm gnum*deb`
```
--------------------------------
### Initialize Python Plugin Module
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Minimal boilerplate for the Python file that defines the plugin's function dictionary.
```python
# my-func.py
#
from Gnumeric import GnumericError GnumericErrorVALUE
import Gnumeric
import string
example_functions = {
}
```
--------------------------------
### Configure and implement write callback
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-export.txt
Set the required write callback function and define its signature for handling output data.
```C
FILE *file;
stf_export_options_set_write_callback (export_options, my_write_func, file);
```
```C
my_write_func (char *string, gpointer data)
{
/* write string to file
* (in this case @data is a FILE* pointer
* so fputs (string, data) would be feasible
*/
}
```
--------------------------------
### Define a help string for a spreadsheet function
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/python-gnumeric.txt
Format the help string using the required @FUNCTION, @SYNTAX, and @DESCRIPTION tags.
```python
help_mid = \
"@FUNCTION=PY_MID\n" \
"@SYNTAX=PY_MID(text,start,num_chars)\n" \
"@DESCRIPTION=" \
"Returns a specific number of characters from a text string, " \
"starting at START and spawning NUM_CHARS. Index is counted " \
"starting from one"
```
--------------------------------
### Execute STF export
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-export.txt
Trigger the export process once all options and callbacks are configured.
```C
stf_export (export_options);
```
--------------------------------
### Create and Destroy Parse Options
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Initialize a new StfParseOptions_t struct and free it after use.
```C
StfParseOptions_t *parseoptions;
parsoptions = stf_parse_options_new ();
```
```C
stf_parse_options_free (parseoptions);
```
--------------------------------
### Convert RangeRef to coordinate tuples
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Helper function to extract start and end coordinates from a Gnumeric RangeRef using the built-in column and row functions.
```python
def range_ref_to_tuples(range_ref):
'''I need a function to find the bounds of a RangeRef. This one
extracts them from the Gnumeric "column" and "row" commands, and
returns them as a pair of tuples. Surely there is a better way?
For example, return a list of cells??'''
col = Gnumeric.functions['column']
row = Gnumeric.functions['row']
# "column" and "row" take references and return an array of col or row
# nums for each cell in the reference. For example, [[1, 1, 1], [2, 2, 2]]
# for columns and [[2, 3, 4], [2, 3, 4]] for rows.
try:
columns = col(range_ref)
rows = row(range_ref)
begin_col = columns[0][0] - 1
begin_row = rows[0][0] - 1
end_col = columns[-1][-1]
end_row = rows[-1][-1]
# We subtracted 1 from the begin values because in the API,
# indexing begins at 0, while "column" and "row" begin at 1.
# We did NOT subtract 1 from the end values, in order to make
# them suitable for Python's range(begin, end) paradigm.
except TypeError:
raise GnumericError,GnumericErrorVALUE
except NameError: # right name?
raise GnumericError,Gnumeric.GnumericErrorNAME
except RefError: # right name?
raise GnumericError,Gnumeric.GnumericErrorREF
except NumError: # right name?
raise GnumericError,Gnumeric.GnumericErrorNUM
return [ (begin_col, begin_row), (end_col, end_row) ]
```
--------------------------------
### Create and free STF export options
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-export.txt
Initialize the export options structure and free it after use to prevent memory leaks.
```C
StfExportOptions_t *export_options;
export_options = stf_export_options_new ();
```
```C
stf_export_options_free (export_options)
```
--------------------------------
### Execute general parsing
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Performs the parsing operation using the configured options and returns a GSList of results.
```C
GSList *mylist;
mylist = stf_parse_general (parseoptions);
```
--------------------------------
### Implementing and Registering the Fibonacci Formula
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/guile-gnumeric.txt
Demonstrates the implementation of a Fibonacci calculation function in Scheme and its registration as a Gnumeric formula named 'fibo'. It includes the recursive logic for Fibonacci and the `register-function` call with its parameters.
```scheme
;;fibonacci function
;;Usage: =FIBO(number)
;;Calculates the fibonacci number of number.
;; A fibonacci number is the sum of the two preceding numbers
;; in the fibonacci series:
;; (fibonacci 0) => 0
;; (fibonacci 1) => 1
;; (fibonacci 2) => 1
;; (fibonacci 3) => 2
;; (fibonacci 4) => 3
;; (fibonacci 20) => 6765
;; (fibonacci 30) => 832040
(define (fibo k)
(let ((n (value-get-as-int k)))
(letrec ((fibof
(lambda (n a b)
(if (<= n 2)
b
(fibof (- n 1) b (+ a b)))))))
(value-new-float (fibof n 1 1)))))
(register-function
"fibo" "f"
"@FUNCTION=FIBO
@SYNTAX=FIBO(num)
@DESCRIPTION=Returns the fibonnacci computation for number."
"Guile"
fibo)
```
--------------------------------
### STF Export Configuration and Execution
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-export.txt
Functions for initializing, configuring, and executing the STF export process.
```APIDOC
## STF Export API
### Description
Functions to manage the lifecycle of an STF export operation, including setting formatting options and defining the output callback.
### Methods
- **stf_export_options_new()**: Creates a new StfExportOptions_t struct.
- **stf_export_options_free(StfExportOptions_t *options)**: Frees the export options struct.
- **stf_export_options_sheet_list_add(StfExportOptions_t *options, Sheet *sheet)**: Adds a sheet to the export list.
- **stf_export_options_sheet_list_clear(StfExportOptions_t *options)**: Clears the sheet list.
- **stf_export_options_set_write_callback(StfExportOptions_t *options, void (*func)(char*, gpointer), gpointer data)**: Sets the callback routine for writing data.
- **stf_export(StfExportOptions_t *options)**: Executes the export process.
### Configuration Options
- **Terminator Types**: TERMINATOR_TYPE_LINEFEED (\n), TERMINATOR_TYPE_RETURN (\r), TERMINATOR_TYPE_RETURN_LINEFEED (\r\n).
- **Quoting Modes**: QUOTING_MODE_AUTO, QUOTING_MODE_ALWAYS, QUOTING_MODE_NEVER.
```
--------------------------------
### Create Debian Packages for Gnumeric
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Creates .deb packages for Gnumeric after building the source on Debian.
```bash
`./debian/rules binary`
```
--------------------------------
### Build Gnumeric Source (Debian)
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Builds the Gnumeric source package on Debian systems.
```bash
`apt-get source gnumeric`
```
```bash
`cd gnumeric-_$version_`
```
```bash
`debian/rules build`
```
--------------------------------
### Perform CSV Parsing
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Configure CSV parsing parameters and execute the parsing routine.
```C
stf_parse_options_set_type (parseoptions, PARSE_TYPE_CSV);
stf_parse_options_csv_set_separators (parseoptions, ";", NULL);
stf_parse_options_csv_set_stringindicator (parseoptions, '"');
stf_parse_options_csv_set_duplicates (parseoptions, FALSE);
```
```C
GSList *mylist;
mylist = stf_parse_general (parseoptions);
```
--------------------------------
### Registering a Custom Formula with Guile
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/guile-gnumeric.txt
This snippet shows how to register a new formula named 'sign' that accepts a single floating-point argument. It includes the formula's name, argument type, description, and the Scheme function to be executed.
```scheme
(register-function
"sign" "f"
"@FUNCTION=SIGN
@SYNTAX=SIGN(number)
@DESCRIPTION=Returns -1 if NUMBER is less than 0, 1 if NUMBER
is greater than 0 and 0 if NUMBER is equal 0.")
```
--------------------------------
### Define a basic addition function in Python
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Initial implementation of a function to add two numbers and its registration dictionary.
```python
_# Add two numbers together_
def func_add(num1, num2):
return num1 + num2
_# Translate the func_add python function to a gnumeric function and register it_
example_functions = {
'py_add': func_add
}
```
--------------------------------
### Gnumeric: Displaying Numbers as Percentages
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/excel-format-doc.txt
To display numbers as percentages, include the percent sign (%) in the number format. The number will be multiplied by 100 and the percent sign will be appended.
```text
%
```
--------------------------------
### Define Plugin XML Configuration
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Template for the plugin.xml file required to register a Python module with Gnumeric.
```xml
Other Python functions from HOWTO
A few extra python functions demonstrating the API.
Local Python
```
--------------------------------
### Register multiple functions with range support
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Update the registration dictionary and XML configuration to include multiple functions including range types.
```python
example_functions = {
'py_add': ('ff','num1,num2',func_add),
'py_sum': ('r', 'values', func_sum)
}
```
```xml
```
--------------------------------
### Checkout and Build Gnumeric from CVS
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Checks out and builds the Gnumeric source code from CVS HEAD. Includes system-specific autogen.sh flags.
```bash
`cvs -z3 checkout gnumeric -d gnumeric-head`
```
```bash
`cd gnumeric-head`
```
```bash
RedHat: `./autogen.sh` and wait while it compiles
```
```bash
Debian: `./autogen.sh --prefix=/usr --with-gconf-schema-file-dir=/etc/gconf/schemas`
```
```bash
`make`
```
```bash
**Optional:** _$root_ `make install`
```
--------------------------------
### STF Parser Configuration
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Functions for creating, destroying, and configuring the base parsing options for the Gnumeric STF parser.
```APIDOC
## STF Parser Configuration
### Description
Functions to initialize and configure the StfParseOptions_t structure.
### Methods
- stf_parse_options_new(): Creates a new StfParseOptions_t struct.
- stf_parse_options_free(parseoptions): Frees the memory of the parse options struct.
- stf_parse_options_set_type(parseoptions, parsetype): Sets the parsing method (PARSE_TYPE_CSV or PARSE_TYPE_FIXED).
- stf_parse_options_set_line_terminator(parseoptions, char): Sets the character used to separate rows.
- stf_parse_options_set_trim_spaces(parseoptions, trim_type): Configures whitespace trimming (TRIM_TYPE_NEVER, TRIM_TYPE_LEFT, TRIM_TYPE_RIGHT).
```
--------------------------------
### Configure fixed-width column split positions
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Sets absolute character positions to define column boundaries for fixed-width parsing.
```C
stf_parse_options_fixed_splitpositions_clear (parseoptions);
stf_parse_options_fixed_splitpositions_add (parseoptions, 6);
stf_parse_options_fixed_splitpositions_add (parseoptions, 11);
stf_parse_options_fixed_splitpositions_add (parseoptions, 18);
stf_parse_options_fixed_splitpositions_add (parseoptions, 20);
stf_parse_options_fixed_splitpositions_add (parseoptions, 24);
```
--------------------------------
### Configure Space Trimming
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Control how excess spaces are removed from parsed text.
```C
stf_parse_options_set_trim_spaces (parseoptions, TRIM_TYPE_NEVER);
stf_parse_options_set_trim_spaces (parseoptions, TRIM_TYPE_LEFT);
stf_parse_options_set_trim_spaces (parseoptions, TRIM_TYPE_RIGHT);
stf_parse_options_set_trim_spaces (parseoptions, TRIM_TYPE_LEFT | TRIM_TYPE_RIGHT);
```
--------------------------------
### Gnumeric/GOffice Elements and Attributes in ODF 1.0, 1.1, and 1.2
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/odf-foreign.txt
Elements and attributes added by Gnumeric and GOffice to ODF 1.0, 1.1, and 1.2 files.
```APIDOC
## Gnumeric/GOffice Elements and Attributes in ODF 1.0, 1.1, and 1.2
### Description
This section details elements and attributes added by Gnumeric and GOffice to ODF files, compatible with versions 1.0, 1.1, and 1.2.
### Elements and Attributes Added by GOffice:
- **gnm:engineering** (attribute to ``)
- Description: A value of "true" indicates that the exponent will always be a multiple of 3. (In ODF 1.3, this will be replaced by `number:exponent-base=1` ("false") or `=3` ("true")).
- **gnm:max-denominator-digits** (attribute to ``)
- Description: Gives the maximum number of denominator digits to be used. (In ODF 1.3, this will be replaced by `number:max-denominator-value`).
### Attribute Values Added by Gnumeric:
- **gnm:step-start**
- Description: In ODF 1.3, this will be `step-end`.
- **gnm:step-end**
- Description: In ODF 1.3, this will be `step-start`.
- **gnm:step-center-x**
- Description: In ODF 1.3, this remains `step-center-x`.
- **gnm:step-center-y**
- Description: In ODF 1.3, this remains `step-center-y`.
- **Various attribute values specifying chart:interpolation types**
```
--------------------------------
### Login to CVS
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Logs into the anonymous CVS server. No password is required; press RETURN.
```bash
`cvs login`
```
--------------------------------
### Set Parsing Method
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Define the parsing method as either CSV or fixed width.
```C
stf_parse_options_set_type (parseoptions, parsetype);
```
--------------------------------
### Interact with Workbooks, Sheets, and Cells
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Commands to retrieve workbook data, access sheets, and modify cell content.
```python
# Get a workbook
>>> wb=Gnumeric.Workbooks()[0]
>>> wb
>>> dir(wb)
>>> ['get_sheets']
# Get a sheet
>>> s=wb.get_sheets()[0]
>>> s
>>> dir(s)
['cell_fetch', 'get_extent', 'get_name_unquoted', 'rename',
'style_apply_range', 'style_get', 'style_set_pos', 'style_set_range']
# Get a cell. s.cell_fetch(0,0) and s[0,0] are synonyms. First
# coordinate is columns, i.e. s[1,0] is B1.
>>> c=s[0,0]
>>> c
|
>>> dir(c)
['get_entered_text', 'get_mstyle', 'get_rendered_text', 'get_value',
'get_value_as_string', 'set_text']
# Change the cell - it changes in the grid
>>> c.set_text('foo')
```
--------------------------------
### Manage sheet list for export
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-export.txt
Add sheets to the export list or clear the existing list.
```C
Sheet *sheet;
stf_export_options_sheet_list_add (export_options, sheet);
```
```C
stf_export_options_sheet_list_clear (export_options);
```
--------------------------------
### Add GUI metadata to Python function
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Include a docstring header within the function to provide descriptions and syntax information for the Gnumeric GUI.
```python
_# Add two numbers together_
def func_add(num1, num2):
'@FUNCTION=PY_ADD\n'\
'@SYNTAX=py_add(num1, num2)\n'\
'@DESCRIPTION=Adds two numbers together.\n'\
'Look, the description can go onto other lines.\n\n'\
'@EXAMPLES=To add two constants, just type them in: py_add(2,3)\n'\
'To add two cells, use the cell addresses: py_add(A1,A2)\n\n'\
'@SEEALSO='
return num1 + num2
```
--------------------------------
### Apply style to a sheet range
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/Styles.txt
Attach a style to a sheet region, either by overlaying it or replacing existing styles.
```C
/* Overlay a partially specified style onto the current style */
sheet_style_apply_range (sheet, range, style);
/* Use the fully specified style in place of the current style
sheet_style_set_range (sheet, range, style);
sheet_style_set_pos (sheet, col, row, style);
```
--------------------------------
### Register function in plugin.xml
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
XML configuration entry required to expose the Python function to Gnumeric.
```xml
```
--------------------------------
### Manage style reference counting in caches
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/Styles.txt
When caching styles, ensure the reference count is incremented upon retrieval and decremented when the cache is flushed.
```C
GnmStyle *cache = cache_lookup_fn (gnm_style_cache);
if (!cache) { /* We must create the style */
cache = gnm_style_new ();
gnm_style_set_font_bold (cache, bold);
cache_insert_fn (gnm_style_cache, cache);
}
gnm_style_ref (cache); /* NB. */
return cache;
```
--------------------------------
### Retrieve a style from a sheet or cell
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/Styles.txt
Obtain a style reference. Note that these functions do not increment the reference count.
```C
GnmStyle const *style = sheet_style_get (sheet, col, row);
or
GnmStyle const *style = cell_get_style (cell);
```
--------------------------------
### Autodiscover fixed-width columns
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Automatically detects column boundaries based on provided text lines.
```C
stf_parse_options_fixed_autodiscover (parseoptions, lines, text);
```
--------------------------------
### Avoid redundant style creation
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/Styles.txt
Build up a style object completely before applying it to a cell to prevent creating unnecessary style regions.
```C
GnmStyle *style = gnm_style_new ();
gnm_style_set_font_name (style, "dingbats");
cell_set_style (cell, style);
style = gnm_style_new ();
gnm_style_set_font_bold (style, TRUE);
cell_set_style (cell, style);
```
--------------------------------
### Define a Python spreadsheet function
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/python-gnumeric.txt
Implement a function that accepts a context and parameters to perform calculations.
```python
def gnumeric_mid(context, text, start_num, num_chars):
return text[start_num-1:start_num+num_chars-1];
```
--------------------------------
### Set CVS Root for Gnome
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Sets the CVSROOT environment variable to the anonymous CVS server for Gnome projects.
```bash
`export CVSROOT=:pserver:anonymous@anoncvs.gnome.org:/cvs/gnome`
```
--------------------------------
### Gnumeric/GOffice Elements and Attributes in Any ODF File
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/odf-foreign.txt
Elements and attributes added by Gnumeric and GOffice that can appear in any ODF file.
```APIDOC
## Gnumeric/GOffice Elements and Attributes in Any ODF File
### Description
This section details elements and attributes added by Gnumeric and GOffice that are applicable to any ODF file.
### Obsolete Elements:
- **gnm:regression-curve** (element)
- Description: Used instead of `chart:regression-curve` for any second or later regression curve in a plot. This is unnecessary as ODF allows multiple `chart:regression-curve` elements.
### Elements and Attributes Added by GOffice:
- **gnm:display-factor="pi"** (attribute to `number:fraction`)
- Description: Indicates a pi-fraction (a fraction written as a multiple of pi).
- **gnm:format-magic** (attribute to `` and ``)
- Description: Specifies Gnumeric's magic number for the style. The magic number is stored as an integer. When this attribute is set, the `number:source` attribute is also set to "language". On import, this magic number is only used if `number:source` is still set to "language".
- **gnm:truncate-on-overflow** (attribute to ``, ``, and ``)
- Description: A value of "false" indicates that this item is not restricted to its natural range and is used for elapsed time. Defaults to "true". Note that ODF has the attribute `number:truncate-on-overflow` for `` with a similar effect but unclear specification. For elements where `gnm:truncate-on-overflow` is not set, `number:truncate-on-overflow` applies.
### Elements and Attributes Added by Gnumeric:
- **gnm:border-line-style-top**
- **gnm:border-line-style-bottom**
- **gnm:border-line-style-left**
- **gnm:border-line-style-right**
- **gnm:diagonal-bl-tr-line-style**
- **gnm:diagonal-tl-br-line-style**
- Description: These are attributes of `` giving the Gnumeric code for the appropriate border as created by `odf_get_gnm_border_format`.
- **gnm:GnmVAlign** (attribute of ``)
- Description: Adds to the "automatic" value of `style:vertical-align`. Possible values are any GnmVAlign enumeration values other than `VALIGN_TOP`, `VALIGN_BOTTOM`, `VALIGN_CENTER`.
- **gnm:GnmHAlign** (attribute of ``)
- Description: Clarifies the "start" value of `style:text-align`. Possible values are any GnmHAlign enumeration values other than `HALIGN_LEFT`, `HALIGN_RIGHT`, `HALIGN_CENTER`, `HALIGN_JUSTIFY`, `HALIGN_FILL`.
- **gnm:input-title**
- **gnm:input-msg**
- Description: Attributes of `` giving the input title and message. These are currently ignored on import.
- **gnm:outliers**
- **gnm:radius-ratio**
- Description: Attributes for the plot-style `gnm:box`.
- **gnm:default-separation**
- Description: An attribute for the plot-style `chart:circle`.
- **gnm:expression**
- Description: Attribute used instead of `table:cell-range` in chart titles.
- **gnm:font-stretch-pango**
- **gnm:font-gravity-pango**
- Description: Attributes to `chart:text-properties`.
- **gnm:label-cell-expression**
- Description: Used instead of `chart:label-cell-address` if that isn't just a range reference.
- **gnm:droplines** (element)
- Description: Adds droplines to charts.
- **gnm:multi-series** (flag)
- Description: Recognizes an XLSurfacePlot export.
- **gnm:vary-style-by-element** (property)
- Description: Plot property.
- **gnm:show-negatives** (property)
- Description: Property of bubble plots.
- **gnm:regression-affine** (property)
- Description: Indicates whether a given regression is affine or not.
- **gnm:regression-polynomial-dims** (property)
- Description: Dimension for a polynomial regression.
```
--------------------------------
### Gnumeric Summary Structure
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/saving.txt
Defines the structure for summary information, containing a list of named items with integer or string values.
```text
Summary
Item[]
name
val-int / val-string ( + val-datestamp in future )
```
--------------------------------
### Gnumeric: Repeating Characters to Fill Column Width
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/excel-format-doc.txt
Include an asterisk (*) in a number format to repeat the next character enough times to fill the column width.
```text
*
```
--------------------------------
### Gnumeric/GOffice Attributes in ODF 1.0 and 1.1
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/odf-foreign.txt
Attributes added by GOffice and Gnumeric to ODF 1.0 and 1.1 files.
```APIDOC
## Gnumeric/GOffice Attributes in ODF 1.0 and 1.1
### Description
This section details attributes added by GOffice and Gnumeric to specific ODF elements in versions 1.0 and 1.1.
### Attributes Added by GOffice:
- **gnm:no-integer-part** (attribute to ``)
- Description: Determines whether an integer portion is shown or not. Defaults to "false" (i.e., an integer part is shown).
- **gnm:am-suffix**, **gnm:pm-suffix** (attributes to ``)
- Description: Determine the suffixes to be used for AM/PM.
### Attributes Added by Gnumeric:
- **gnm:reverse-direction**
- **gnm:automatic-content**
- **gnm:display-equation**
- **gnm:display-r-square**
- Description: These attributes are used instead of the ODF 1.2 attribute `chart:...`.
```
--------------------------------
### Retrieve Gnumeric Cell Values
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Demonstrates two methods for accessing cell values within the Gnumeric Python console.
```python
>>> c.get_value()
foo
>>> s.cell_fetch(0,0).get_value()
foo
```
--------------------------------
### CSV Parsing Configuration
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Functions to configure CSV-specific parsing behavior including separators and string indicators.
```APIDOC
## CSV Parsing Configuration
### Description
Configures how the parser handles CSV data, including column separators and string indicators for handling data containing separators.
### Methods
- stf_parse_options_csv_set_separators(parseoptions, separators, NULL): Defines the characters used as column separators.
- stf_parse_options_csv_set_stringindicator(parseoptions, char): Sets the character used to enclose strings containing separators.
- stf_parse_options_csv_set_duplicates(parseoptions, boolean): Sets whether duplicate separators are treated as a single separator.
- stf_parse_general(parseoptions): Executes the parsing process and returns a GSList of parsed data.
```
--------------------------------
### Retrieving Gnumeric Value Data in Guile
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/guile-gnumeric.txt
Shows the functions used to extract data from Gnumeric value smobs based on their type. These are used within custom Scheme functions to process input arguments received from Gnumeric.
```scheme
(value_get_as_bool scm)
```
```scheme
(value_get_as_checked_bool scm)
```
```scheme
(value_get_as_string scm)
```
```scheme
(value_get_as_int scm)
```
```scheme
(value_get_as_list scm)
```
--------------------------------
### Configure Line Terminator
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Specify a custom character to act as the row separator.
```C
stf_parse_options_set_line_terminator (parseoptions, '\r');
```
--------------------------------
### Explore Gnumeric Python API
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Interactive Python commands to inspect the Gnumeric module and its available classes.
```python
>>> import Gnumeric
>>> dir()
>>> dir(Gnumeric)
```
--------------------------------
### Modify GnmStyle attributes
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/Styles.txt
Set specific style properties like font name. Internal hashing and ref-counting are handled automatically for font names.
```C
gnm_style_set_font_name (style, "Dingbats");
```
--------------------------------
### Gnumeric StyleShade Structure
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/saving.txt
Defines shading patterns for cells.
```text
StyleShade
pattern
```
--------------------------------
### Gnumeric Style Structure
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/saving.txt
Details the components of a Style object, which holds rendering information.
```text
Style
StyleFormat format
StyleFont font
StyleBorder border
StyleShade shading
int halign
int valign
int orientation
```
--------------------------------
### Define function with explicit argument types
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/starting-with-python.html
Update the registration dictionary to specify argument types and names for better Gnumeric integration.
```python
'py_add': ('ff','num1,num2',func_add)
```
--------------------------------
### Gnumeric ColRowInfo Structure
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/saving.txt
Contains information about column or row properties, such as position, style, and units.
```text
ColRowInfo
int pos
Style style
int units
int pixels
```
--------------------------------
### Register a spreadsheet function
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/python-gnumeric.txt
Use gnumeric.register_function to expose the Python function to the Gnumeric spreadsheet engine.
```python
gnumeric.register_function("py_mid", "Plugin demo", "sff", "text,
start_num, num_chars", help_mid, gnumeric_mid);
```
--------------------------------
### Track Modification State
Source: https://github.com/gnome/gnumeric/blob/master/doc/developer/stf-parser.txt
Monitor changes to the parse options struct between function calls.
```C
stf_parse_options_before_modification (parseoptions);
/* make some changes to the parseoptions with the set functions calls */
if (stf_parse_options_after_modification (parseoptions)) {
/* The parse options contents have changed...do something */
}
```
```C
stf_parse_options_before_modification (parseoptions);
stf_parse_options_fixed_splitpositions_clear (parseoptions);
stf_parse_options_fixed_splitpositions_add (parseoptions, 5);
stf_parse_options_fixed_splitpositions_add (parseoptions, 7);
stf_parse_options_fixed_splitpositions_add (parseoptions, 9);
stf_parse_options_after_modification (parseoptions);
``` |