Did you know ... Search Documentation:
Pack odf_sheet -- prolog/ods/sheet.pl
PublicShow source

This module loads an Open Document spreadsheet into the Prolog database. The primary call is ods_load/1, which adds the following facts into the calling module:

  • sheet(Sheet, Style)
  • col(Sheet, X, Style)
  • row(Sheet, Y, Style)
  • cell(Sheet, Id, Value, Type, Formula, Style, Annotation)
  • span(Id, IdBase)
  • style(Name, XMLDOM)

In addition, it provides the following high-level query primitives: cell_value/4, cell_type/4, cell_formula/4, cell_eval/4 and cell_style/4. All these predicates use the same calling convention, e.g.,

cell_value(Sheet, X, Y, Value)

where Sheet is the name of the sheet, X is the column (an integer) and Y is the row (an integer). Value is the current value of the cell. Although integer columns are easier for computation, these predicates do allow specifying the column as an atom. E.g., the value of cell WindOffshore.D43 can be requested using the call below. This is mainly intended for querying from the toplevel.

?- cell_value('WindOffshore', d, 43, X).
X = 0.07629.

Values are represented using the following conventions:

  • Textual values are represented using an atom
  • Numerical values are represented using Prolog numbers
  • Booleans are represented as @true or @false
  • Errors are representated as #(Error)
To be done
- Add interface to query cell spanning
- Correctly report cell boolean and error values.
 ods_DOM(+File, -DOM, +Options) is det
DOM is the XML domtree of the content file of the given ODS document.
 ods_load(:Data)
Load a spreadsheet. Data is either a parsed XML DOM, a file name or a URI. Tables in the spreadsheet are converted into a set of Prolog predicates in the calling module. The generated predicates are:
  • sheet(Name, Style)
  • col(Table, X, Style)
  • row(Table, Y, Style)
  • cell(Table, ID, Value, Type, Formula, Style, Annotation)
  • span(ID, IDBase)
  • style(Style, Properties)

Does nothing if the spreadsheet is already loaded in the target module. To force reloading, first use ods_unload/0.

 cell_id(+X, +Y, -ID) is det
cell_id(-X, -Y, +ID) is det
 ods_style_property(:Style, ?Property) is nondet
True when Property is a property of Style. Currently extracted styles are:
font_weight(Weight)
Font weight (e.g., bold)
font_name(Name)
Name of the font used for the text
font_size(Size)
Size of the font. See below for size representations.
column_width(Width)
Width of the column
cell_color(Color)
Color of the cell background
name(Name)
Name of the style.

Sizes are expressed as one of pt(Points), cm(Centimeters) or mm(Millimeters)

See also
- http://docs.oasis-open.org/office/v1.2/OpenDocument-v1.2-part1.html
To be done
- Normalize sizes?
 sheet_name_need_quotes(+Name) is semidet
True when Name is a sheet name that needs (single) quotes.
 cell_value(:Sheet, ?X, ?Y, ?Value)
True when cell X,Y in Sheet has Value.
 cell_type(:Sheet, ?X, ?Y, ?Type)
True when cell X,Y in Sheet has Type.
 cell_formula(:Sheet, ?X, ?Y, ?Formula)
True when cell X,Y in Sheet has Formula.
 cell_eval(:Sheet, ?X, ?Y, ?Value)
True when the formula of cell X,Y in Sheet evaluates to Value
 cell_style(:Sheet, ?X, ?Y, ?Style)
True when cell X,Y in Sheet has style property Style. See ods_style_property/2 for supported styles.
 cell(:Sheet, ?X, ?Y, ?Value, ?Type, ?Formula, ?Style, ?Annotations)
Query raw cells.
 ods_eval(:Expression, -Value) is det
Evaluate an expression.
 column_name(?Index, ?Name) is det
Name is the alplanumerical name of column Col. Column 1 is 'A', 26 = 'Z', 27 = 'AA'.
 ods_unload
Remove saved facts from the database
 ods_unload_all is det
Unload all currently loaded spreadsheets.
 ods_compile
Lock the spreadsheet predicates as static to make them faster.
 ods_compile_all is det
Compile all loaded spreadsheets
 ods_current(:URL) is nondet
True when URL is the currently loaded spreadsheet.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 ods_reference(Arg1, Arg2, Arg3, Arg4)