|
> > | <--
Contributions to this plugin are appreciated. Please update the plugin page
at http://twiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin or provide feedback
at http://twiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev.
If you are a TWiki contributor please update the plugin in the SVN repository.
--> |
| TWiki Spreadsheet Plugin |
|
< < | This Plugin adds spreadsheet capabilities to The Caboteria topics. Formulae like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables. In other words, this Plugin provides general formula evaluation capability, not just classic spreadsheet functions. |
> > | This plugin adds spreadsheet capabilities to TWiki topics. Formulae like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables. In other words, this plugin provides general formula evaluation capability, not just classic spreadsheet functions. |
|
|
| |
|
< < | The formula next to "Total" is %CALC{"$SUM( $ABOVE() )"}% . (you see the formula instead of the sum in case the Plugin is not installed or not enabled.) |
> > | The formula next to "Total" is %CALC{"$SUM( $ABOVE() )"}% . (you see the formula instead of the sum in case the plugin is not installed or not enabled.) |
|
Syntax Rules |
|
< < | The action of this Plugin is triggered by the %CALC{"..."}% variable, which gets rendered according to the built-in function(s) found between the quotes. |
> > | The action of this plugin is triggered by the %CALC{"..."}% variable, which gets rendered according to the built-in function(s) found between the quotes. |
|
- Built-in function are of format
$FUNCNAME(parameter)
- Functions may be nested, e.g.
%CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
|
|
- Lists can refer to values and/or table cell ranges, e.g.
%CALC{"$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )"}%
- Formulae can only reference cells in the current or preceeding row of the current table; they may not reference cells below the current table row
- Formulae can also be placed outside of tables; they can reference cells in the preceeding table
|
|
> > | |
|
Built-in Functions |
| |
|
> > |
EMPTY( text ) -- test for empty text
- Returns
1 if text is empty, or 0 if not
- Syntax:
$EMPTY( text )
- Example:
%CALC{"$EMPTY(foo)"}% returns 0
- Example:
%CALC{"$EMPTY()"}% returns 1
- Example:
%CALC{"$EMPTY($TRIM( ))"}% returns 1
- Related:
$EXACT() , $IF() , $TRIM()
|
|
EVAL( formula ) -- evaluate a simple mathematical formula
- Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
|
|
- Syntax:
$EXACT( text1, text2 )
- Example:
%CALC{"$EXACT(foo, Foo)"}% returns 0
- Example:
%CALC{"$EXACT(foo, $LOWER(Foo))"}% returns 1
|
|
< < | |
> > | |
|
EXEC( formula ) -- execute a spreadsheet formula |
|
- Syntax:
$EXISTS( topic )
- Example:
%CALC{"$EXISTS(WebHome)"}% returns 1
- Example:
%CALC{"$EXISTS(ThisDoesNotExist)"}% returns 0
|
|
> > | |
|
EXP( num ) -- exponent (e) raised to the power of a number |
|
- Example:
%CALC{"$FIND(f, fluffy)"}% returns 1
- Example:
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
- Example:
%CALC{"$FIND(@, fluffy, 1)"}% returns 0
|
|
< < | |
> > | |
|
FORMAT( type, precision, number ) -- format a number to a certain type and precision |
|
- Example:
%CALC{"$IF($T(R1:C5) > 1000, Over Budget, OK)"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
- Example:
%CALC{"$IF($EXACT($T(R1:C2),), empty, $T(R1:C2))"}% returns the content of R1:C2 or empty if empty
- Example:
%CALC{"$SET(val, $IF($T(R1:C2) == 0, zero, $T(R1:C2)))"}% sets a variable conditionally
|
|
< < | |
> > |
INSERTSTRING( text, start, new ) -- insert a string into a text string
- Insert
new string into text string text to the right of start position. Position starts at 1; use a negative start to count from the end of the text
- Syntax:
$INSERTSTRING( text, start, new )
- Example:
%CALC{"$INSERTSTRING(abcdefg, 2, XYZ)"}% returns abXYZcdefg
- Example:
%CALC{"$INSERTSTRING(abcdefg, -2, XYZ)"}% returns abcdeXYZfg
- Related:
$FIND() , $LEFTSTRING() , $REPLACE() , $RIGHTSTRING() , $SEARCH() , $SUBSTITUTE() , $SUBSTRING() , $TRANSLATE()
|
|
INT( formula ) -- evaluate formula and round down to nearest integer |
|
- Example:
%CALC{"$SUM($LEFT())"}% returns the sum of cells to the left of the current cell
- Related:
$ABOVE() , $RIGHT()
|
|
> > |
LEFTSTRING( text, num ) -- extract characters at the beginning of a text string |
|
LENGTH( text ) -- length of text in bytes |
|
- Example:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
- Example:
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , E)"}% returns non-empty elements A, B, E
- Example:
%CALC{"$LISTIF($index > 2, A, B, C, D)"}% returns C, D
|
|
< < | |
> > |
- Related:
$EMPTY() , $EXACT() , $IF() , $LIST() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
|
|
LISTITEM( index, list ) -- get one element of a list |
|
NOP( text ) -- no-operation |
|
< < |
- Useful to change the order of Plugin execution. For example, it allows preprossing to be done before
%SEARCH{}% is evaluated. The percent character '%' can be escaped with $per
|
> > |
- Useful to change the order of plugin execution. For example, it allows preprossing to be done before
%SEARCH{}% is evaluated. The percent character '%' can be escaped with $per
|
|
|
|
- Returns 0 if
num is not zero, 1 if zero
- Syntax:
$NOT( num )
- Example:
%CALC{"$NOT(0)"}% returns 1
|
|
< < | |
> > | |
|
ODD( num ) -- test for odd number |
|
PROPERSPACE( text ) -- properly space out WikiWords |
|
< < |
- Properly spaces out WikiWords preceeded by white space, parenthesis, or
][ . Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded
|
> > |
- Properly spaces out WikiWords preceeded by white space, parenthesis, or
][ . Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE plugins setting are excluded
|
|
- Syntax:
$PROPERSPACE( text )
- Example: Assuming DONTSPACE contains MacDonald:
%CALC{"$PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh)"}% returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh
- Related:
$LOWER() , $PROPER() , $TRIM() , $UPPER()
|
|
- Replace
num number of characters of text string text , starting at start , with new text new . Starting position is 1; use a negative start to count from the end of the text
- Syntax:
$REPLACE( text, start, num, new )
- Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
|
|
< < | |
> > | |
|
RIGHT( ) -- address range of cells to the right of the current cell |
|
- Example:
%CALC{"$SUM($RIGHT())"}% returns the sum of cells to the right of the current cell
- Related:
$ABOVE() , $LEFT()
|
|
> > |
RIGHTSTRING( text, num ) -- extract characters at the end of a text string |
|
ROUND( formula, digits ) -- round a number
- Evaluates a simple
formula and rounds the result up or down to the number of digits if digits is positive; to the nearest integer if digits is missing; or to the left of the decimal point if digits is negative
|
|
- Example:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
- Example:
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
- Example:
%CALC{"$SEARCH([abc], fluffy,)"}% returns 0
|
|
< < | |
> > | |
|
SET( name, value ) -- set a variable for later use |
|
- Example:
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
- Example:
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
- Example:
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
|
|
< < | |
> > |
SUBSTRING( text, start, num ) -- extract a substring out of a text string
- Extract
num number of characters of text string text , starting at start . Starting position is 1; use a negative start to count from the end of the text
- Syntax:
$SUBSTRING( text, start, num )
- Example:
%CALC{"$SUBSTRING(abcdefghijk, 3, 5)"}% returns cdefg
- Related:
$FIND() , $INSERTSTRING() , $LEFTSTRING() , $REPLACE() , $RIGHTSTRING() , $SEARCH() , $SUBSTITUTE() , $TRANSLATE()
|
|
SUM( list ) -- sum of a list or range of cells |
|
- Syntax:
$TRANSLATE( text, from, to )
- Example:
%CALC{"$TRANSLATE(boom,bm,cl)"}% returns cool
- Example:
%CALC{"$TRANSLATE(one, two,$comma,;)"}% returns one; two
|
|
< < | |
> > | |
|
TIME( text ) -- convert a date string into a serialized date number |
|
- Removes all spaces from text except for single spaces between words
- Syntax:
$TRIM( text )
- Example:
%CALC{"$TRIM( eat spaces )"}% returns eat spaces
|
|
< < | |
> > | |
|
UPPER( text ) -- upper case string of a text |
|
FAQ |
|
> > | |
| Can I use CALC in a formatted search?
Specifically, how can I output some conditional text in a FormattedSearch? |
|
|
|
< < | Above table is created manually. Another Plugin could build the table dynamically, e.g. by pulling data out of a bug tracking system. The Spreadsheet Plugin can be used to display table data statistics. |
> > | Above table is created manually. Another plugin could build the table dynamically, e.g. by pulling data out of a bug tracking system. The Spreadsheet plugin can be used to display table data statistics. |
|
Plugin Settings |
|
data/TWiki/SpreadSheetPlugin.txt |
Plugin topic |
data/TWiki/SpreadSheetPlugin.txt,v |
Plugin topic repository |
lib/TWiki/Plugins/SpreadSheetPlugin.pm |
Plugin Perl module |
|
|
< < |
- TWiki 4 and up: Visit
configure in your TWiki installation, and enable the Plugin in the {Plugins} section.
|
> > |
- TWiki 4 and up: Visit
configure in your TWiki installation, and enable the plugin in the {Plugins} section.
|
|
- Test if the "Total" in the first table in this topic is correct.
Plugin Info
|
|
< < |
Copyright: |
© 2001-2007, Peter Thoeny, TWIKI.NET |
|
> > |
Copyright: |
© 2001-2009, Peter Thoeny, TWIKI.NET |
|
|
|
|
< < |
Plugin Version: |
13 Oct 2007 (15270) |
|
> > |
Plugin Version: |
26 Mar 2009 (17910) |
|
|
Change History: |
<-- specify latest version first --> |
|
|
> > |
26 Mar 2009: |
Added $INSERTSTRING() |
25 Mar 2009: |
Added $EMPTY(), $LEFTSTRING(), $RIGHTSTRING(), $SUBSTRING() |
24 Mar 2009: |
Fixed bug in $REPLACE() if to-be-replaced string is "0"; fixed bug in $SUBSTITUTE() if replace string is empty; improved docs |
|
|
13 Oct 2007: |
Added $FORMATTIMEDIFF() |
09 Sep 2007: |
Enhanced documentation for $EVAL() and $INT() |
02 Jun 2007: |
Added VarCALC to have %CALC{}% listed in TWikiVariables |
|
|
Related Topics: TWikiPreferences, TWikiPlugins, VarCALC |
|
< < | -- TWiki:Main/PeterThoeny - 13 Oct 2007 |
> > | -- TWiki:Main/PeterThoeny - 26 Mar 2009 |