table of contents
sps(3) | AFNIX Module | sps(3) |
NAME¶
sps - standard spreadsheet moduleSTANDARD SPREADSHEET MODULE¶
The Standard Spreadsheet module is an original implementation that provides the necessary objects for designing a spreadsheet. A spreasheet acts a great interface which structure data in the form of record and sheets. Once structured, these data can be indexed, manipulated and exported into various formats. Spreadsheet concepts# an example of file importation 1 "a string" 'a'The previous example shows the file structure that can be used to import cell data. The fist line defines a record with 3 cells. The second line defines also a record with 3 cells. The second cell is a named cell. Record exportation
const sps (afnix:sps:Folio) afnix:sps:folio-p sps # trueThe constructor can operate also by name or by input stream. With a string, a new folio those name is the argument is created. By stream, a new folio is created and loaded with the input stream data. Eventually, the folio name can be set with the set-name command and retrieved with the get-name command.
const sps (afnix:sps:Folio) sps:set-name "planets"Sheet object
const sht (afnix:sps:Sheet) afnix:sps:sheet-p sht # trueWhen the sheet is created, it can be added to the folio spreadsheet with the add method.
const sht (afnix:sps:Sheet "data") sps:add shtAdding data to the sheet
sht:add-data "Mercury" 4840 "1407:36" sht:add-data "Venus" 12400 "5819:51" sht:add-data "Earth" 12756 "23:56" sht:add-data "Mars" 6800 "24:37" sht:add-data "Jupiter" 142800 "9:50" sht:add-data "Saturn" 120800 "10:14" sht:add-data "Uranus" 47600 "10:49" sht:add-data "Neptune" 44600 "15:40" sht:add-data "Pluto" 5850 "153:17" sht:add-data "Sedna" 1800 "960:00"Data can be imported in a sheet by importation with an input stream. During the importation, the serialized data are decoded and placed sequentially in the stream. Sheet sorting
sht:sort 0 sht:sort 1 falseRecord object
const rcd (afnix:sps:Record) afnix:sps:record-p # trueFilling a record
const rcd (Record) rcd:add "Mercury" 4840 "1407:36"For data extraction, the length method returns the record length. Data can be extracted by index with either the get or map method. The get method returns the record cell while the map method returns the cell literal. Object search
# get a sheet by tag const sheet (folio:lookup "the tag")If there are several sheets that matched the tag, the filter method is more appropriate. The filter method returns a new folio that contains the sheet that matches the requested tag.
# get a sub-folio by tag const sf (folio:filter "the tag")Searching for a cell
# get a default xref table const xref (folio:getxref)The cross-reference table can also be built by searching for sheet tags. With a string argument, the getxref search for all sheets that matches the tag and then build a cross-reference table. This method is equivalent to the operation of building a new folio by tag with the filter method and then building the cross-reference table.
# get a xref table by tag const xref (folio:getxref "the tag") # another method const sf (folio:filter "the tag") const xref (sf:getxref)A cross-reference table can also be built by cell index and/or record index. With a cell index, the cross-reference table is built by indexing the sheet column. With both the cell and record indexes, the cross-reference table is built by indexing all cells at the coordinate for all sheets.
# get a xref table by cell index const xref (folio:getxref 0) # get a xref table by cell and record index const xref (folio:getxref 0 1)
STANDARD SPREADSHEET REFERENCE¶
Cellcell-p
Inheritance
Nameable
Constructors
Cell (none)
The Cell constructor create a default cell with no name and no value. When
evaluated, the cell returns nil.
Cell (Literal)
The Cell constructor create a default cell by value. The argument is a literal
object which can be viewed with its string representation.
Cell (String Literal)
The Cell constructor create a default cell by name and value. The first argument
is the cell name. The second argument is a literal object which can be viewed
with its string representation.
Methods
get -> Literal (none)
The get method returns the cell literal value.
set -> none (Literal)
The set method sets the cell literal value.
get-name -> String (none)
The get-name method returns the cell name.
set-name -> none (String)
The set-name method sets the cell name.
Persist
persist-p
Inheritance
Nameable
Methods
save -> none (none)
The save method saves the current object.
saveas -> none (String)
The saveas method saves the current object into the file those name is the
string argument.
Record
record-p
Inheritance
Persist
Constructors
Record (none)
The Record constructor create an empty record with no name and no cell.
Record (String)
The Record constructor create an empty record by name name. The argument is the
record name to use.
Methods
add -> none (Cell|Literal...)
The add method adds one or several cell objects to the record. In the first
form, the argument is a cell that is added in the record. In the second form,
the argument is a literal that is used to create a cell by value.
get -> Cell (Integer)
The get method returns a record cell by index. The index must be within the
record range or an exception is raised.
map -> Literal (Integer)
The map method map a record cell by index. The index must be within the record
range or an exception is raised. The cell is mapped to a literal object.
set -> none (Integer Cell|Literal)
The set method sets the record cell by index. The record index must be valid in
order to succeed. A new cell is created prior the record update. The previous
cell data is lost including its name.
sort -> none (none|Boolean)
The sort method sorts a record in place. Without argument, the record is sorted
in ascending order. The optional boolean argument specifies the sorting mode.
If true, the record is sorting in ascending order and in descending order if
false.
find -> Cell (String)
The find method finds a cell by name. If the cell is not found, the nil object
is returned. This method is similar to the lookup method.
get-index -> Integer (String)
The get-index method finds a cell index by name. If the cell is not found, an
exception is raised. The index is the cell position in the record.
lookup -> Cell (String)
The lookup method finds a cell by name. If the cell is not found, an exception
is raised. This method is similar to the find method.
length -> Integer (none)
The length method returns the record length.
get-name -> String (none)
The get-name method returns the record name.
reset -> none (none)
The reset method rest the record. The record name is not changed but all record
cells are removed.
set-name -> none (String)
The set-name method sets the record name.
Sheet
sheet-p
Inheritance
Persist
Constructors
Sheet (none)
The Sheet constructor create an empty sheet with no name and no cell.
Sheet (String)
The Sheet constructor create an empty sheet by name. The argument is the sheet
name to use.
Sheet (String String)
The Sheet constructor create an empty sheet by name and info. The first argument
is the sheet name to use. The second argument is the sheet information
string.
Methods
add -> none (Record)
The add method adds a record to the sheet.
get -> Record (Integer)
The get method returns a sheet record by index. The index must be within the
sheet range or an exception is raised.
set -> none (Integer Record)
The set method sets the sheet record by index. The sheet index must be valid in
order to succeed.
sort -> none (none|Integer|Boolean|Integer
Boolean)
The sort method sorts the sheet in place. By default, the sheet is sorted in
ascending order with column 0. With one argument, the argument can be either
the sorting mode or the column number. If the mode is true, the sheet is
sorted in ascending mode. If the mode is false, the sheet is sorted in
descending mode. With two arguments, the first argument is the column number
and the second is the sorting mode.
length -> Integer (none)
The length method returns the sheet length.
convert -> PrintTable ([Integer [Integer
[Boolean]]])
The convert method converts the sheet into a print-table representation. Without
argument, the whole sheet is converted. With one argument, the sheet is
converted unto a maximum of rows. The second optional argument is the start
index that default to 0. The third optional argument is the literal format. By
default, the literal is formatted as a string. If the flag is true, the
literal is formatted as a literal string representation.
add-data -> none ([Cell|Literal]+)
The add-data method adds one or several cell object to a sheet record. The sheet
record is initially created and the object elements are added sequentially to
the record. In the first form, the argument is a cell that is added in the
record. In the second form, the argument is a literal that is used to create a
cell by value.
add-marker -> none ([Literal]+)
The add-marker method adds one or several literal objects to a sheet marker
record.
marker-length -> Integer (none)
The marker-length method returns the number of markers defined for this
sheet.
get-marker -> Cell (Integer)
The get-marker method returns a marker cell by index from the sheet marker
record.
set-marker -> none (Integer Literal)
The set-marker method set the sheet marker record by index and literal.
find-marker -> Integer (String)
The find-marker method find the marker index. The argument is the marker string
value.
add-sign -> none ([Literal]+)
The add-sign method adds one or several literal objects to a sheet sign
record.
signature-length -> Integer (none)
The signature-length method returns the number of signs defined for this
sheet.
get-sign -> Cell (Integer)
The get-sign method returns a sign cell by index from the sheet sign
record.
set-sign -> none (Integer Literal)
The set-sign method set the sheet sign record by index and literal.
find-sign -> Integer (String)
The find-sign method find the sign index. The argument is the sign string
value.
add-header -> none (Cell|Literal...)
The add-header method adds one or several cell object to a sheet header record.
In the first form, the argument is a cell that is added in the record. In the
second form, the argument is a literal that is used to create a cell by
value.
get-header -> Cell (Integer)
The get-header method returns a header cell by index from the sheet header
record.
map-header -> Literal (Integer)
The map-header method maps to a literal object a header cell by index from the
sheet header record.
set-header -> none (Integer Literal)
The set-header method set the header record by index and literal. The cell
associated with the header record is updated with the literal value.
add-footer -> none ([Cell|Literal]+)
The add-footer method adds one or several cell object to a sheet footer record.
In the first form, the argument is a cell that is added in the record. In the
second form, the argument is a literal that is used to create a cell by
value.
get-footer -> Cell (Integer)
The get-footer method returns a footer cell by index from the sheet footer
record.
map-footer -> Literal (Integer)
The map-footer method maps to a literal object an footer cell by index from the
sheet footer record.
set-footer -> none (Integer Literal)
The set-footer method set the footer record by index and literal. The cell
associated with the footer record is updated with the literal value.
get-name -> String (none)
The get-name method returns the sheet name.
set-name -> none (String)
The set-name method sets the sheet name.
get-info -> String (none)
The get-info method returns the sheet info.
set-info -> none (String)
The set-info method sets the sheet info.
add-tag -> none ([String]+)
The add-tag method adds a tag into the tags vector. The tag can be used to mark
a sheet in a folio.
tag-p -> Boolean (string)
The tag-p method returns true if the given tag is defined for this sheet.
tag-length -> Integer (none)
The tag-length method returns the number of tags defined for this sheet.
get-tag -> String (Integer)
The get-tag method returns a tag by index.
set-tag -> none (Integer Literal)
The set-tag method set the sheet tag record by index and literal.
find-tag -> Integer (String)
The find-tag method find the tag index. The argument is the tag string
value.
reset -> none (none)
The reset method resets the sheet. The name and information is unchanged during
this operation.
Folio
folio-p
Inheritance
Persist
Constructors
Folio (none)
The Folio constructor create an empty folio with no name and no cell.
Folio (String)
The Folio constructor create an empty folio by name. The argument is the folio
name to use.
Folio (String String)
The Folio constructor create an empty folio by name and info. The first argument
is the folio name to use. The second argument is the folio information
string.
Folio (InputStream)
The Folio constructor create an empty folio and fill it by reading the data from
the input stream. The input stream must have the data in a serialized
form.
Methods
write -> none (OutputStream)
The write method write the folio contents to an output stream. The written form
is a serialized form.
add -> none (Sheet)
The add method adds a sheet to the folio.
get -> Sheet (Integer)
The get method returns a sheet by index. The index must be within the folio
range or an exception is raised.
set -> none (Integer Sheet)
The set method sets the folio by index and sheet. The index must be within the
folio range or an exception is raised.
tag-p -> Boolean (String)
The tag-p method returns true if a sheet with the tag argument exists in the
folio.
find -> Sheet (String)
The find method finds a sheet by tag. The first found sheet those tag is matched
is returned. In the case that multiple sheet share the same tag, the filter
should be used. If no sheet is found the method return the nil object.
lookup -> Sheet (String)
The lookup method finds a sheet by tag. The first found sheet those tag is
matched is returned. In the case that multiple sheet share the same tag, the
filter should be used. If no sheet is found the method throws an exception.
This method is similar to the find method.
filter -> Folio (String)
The filter method return a new folio with sheets that match the argument tag. If
no sheet is found, the folio is empty.
reset -> none (none)
The reset method resets the folio. The name and information is unchanged during
this operation.
length -> Integer (none)
The length method returns the folio length.
get-name -> String (none)
The get-name method returns the folio name.
set-name -> none (String)
The set-name method sets the folio name.
get-info -> String (none)
The get-info method returns the folio info.
set-info -> none (String)
The set-info method sets the folio info.
get-xref -> Xref (none|Integer|String|Integer
Integer)
The get-xref method returns a cross-reference table from the folio. Without
argument, the whole folio is scanned and all named cells are added in the
cross-reference table. With an integer argument, all cells that matches the
cell index argument are added in the cross-reference table. With a string
argument, all cells that have the same name are added in the table. Finally,
with two arguments that represents the cell index and the record index are
used, all cells are added in the table with these two coordinates.
Index
index-p
Inheritance
Object
Constructors
Index (none)
The Index constructor creates an empty index.
Index (Integer)
The Index constructor creates an index with a cell index as its
coordinate.
Index (Integer Integer)
The Integer constructor creates an index with a cell and record indexes as its
coordinate. The first argument is the cell index. The second argument is the
record index.
Index (Integer Integer Integer)
The Index constructor creates an index with a cell, record and sheet indexes as
its coordinate. The first argument is the cell index. The second argument is
the record index. The third argument is the sheet index.
Methods
add -> none (Integer|Integer Integer|Integer
Integer Integer)
The add method adds a new index coordinate in the index object. In the first
form, the cell index is used as the coordinate. In the second form, the cell
and record indexes are used as the coordinate. In the third form, the cell,
record and sheet indexes are used as the coordinate.
reset -> none (none)
The reset method reset the index by removing all attached coordinates.
length -> Integer (none)
The length method returns the index length. The index length is the number of
coordinate entries in the index.
exists-p -> Boolean (Integer|Integer
Integer|Integer Integer Integer)
The exists-p predicate returns true if a coordinate entry exists in the index.
In the first form, the cell index is used as the coordinate. In the second
form, the cell and record indexes are used as the coordinate. In the third
form, the cell, record and sheet indexes are used as the coordinate.
set-index-cell -> none (Integer Integer)
The set-index-cell method sets the cell index by position. The first argument is
the coordinate position. The second argument is the cell index to use.
update-index-cell -> none (Integer)
The update-index-cell method updates the cell index for all entries in the
index. The argument is the new cell index to use for the update process.
get-index-cell -> Integer (Integer)
The get-index-cell method returns the cell index for a particular entry. The
argument is the entry position.
set-index-record -> none (Integer Integer)
The set-index-record method sets the record index by position. The first
argument is the coordinate position. The second argument is the record index
to use.
update-index-record -> none (Integer)
The update-index-record method updates the record index for all entries in the
index. The argument is the new record index to use for the update
process.
get-index-record -> Integer (Integer)
The get-index-record method returns the record index for a particular entry. The
argument is the entry position.
set-index-sheet -> none (Integer Integer)
The set-index-sheet method sets the sheet index by position. The first argument
is the coordinate position. The second argument is the cell sheet to
use.
update-index-sheet -> none (Integer)
The update-index-sheet method updates the sheet index for all entries in the
index. The argument is the new sheet index to use for the update
process.
get-index-sheet -> Integer (Integer)
The get-index-sheet method returns the sheet index for a particular entry. The
argument is the entry position.
Xref
xref-p
Inheritance
Object
Constructors
Xref (none)
The Xref constructor creates an empty cross-reference object.
Methods
add -> none (String [Integer|Integer
Integer|Integer Integer Integer])
The add method adds a new reference in the table. The first argument is always
the index name. In the first form, the cell index is used as the coordinate.
In the second form, the cell and record indexes are used as the coordinate. In
the third form, the cell, record and sheet indexes are used as the
coordinate.
get -> Index (Integer|String)
The get method returns an Index object either by name or position. With an
integer argument, the index is obtained by position. With a string argument,
the index with the matching name is returned.
reset -> none (none)
The reset method resets the cross-reference table.
length -> Integer (none)
The length method returns the length of the cross-reference table.
lookup -> Index (String)
The lookup method returns an index those name is the matching argument. If the
index cannot be found, an exception is raised.
exists-p -> Boolean (String)
The exists-p predicate returns true if an index those name is the matching
argument exists in the cross-reference table.
get-name -> String (Integer)
The get-name method returns the index name by position.
2012-03-26 | AFNIX |