| TWiki Spreadsheet Plugin | |
< < | This Plugin adds speadsheet 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. | > > | 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. | | | | ABS( num ) -- absolute value of a number
- Syntax:
$ABS( num )
- Example:
%CALC{"$ABS(-12.5)"}% returns 12.5
| |
< < | | > > | | |
AND( list ) -- logcial AND of a list | |
| |
< < | EVAL( formula ) -- evaluate a simple formula | > > | EVAL( formula ) -- evaluate a simple mathematical formula | |
- Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
- Syntax:
$EVAL( formula )
- Example:
%CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
| |
< < | | > > |
EVEN( num ) -- test for even number | |
EXACT( text1, text2 ) -- compare two text strings | |
- Example:
%CALC{"$EXACT(foo, $LOWER(Foo))"}% returns 1
- Related:
$IF() , $TRIM()
| |
> > |
EXEC( formula ) -- execute a spreadsheet formula
- Execute a spreadsheet formula, typically retrieved from a variable. This can be used to store a formula in a variable once and execute it many times using different parameters.
- Syntax:
$EXEC( formula )
- Example:
%CALC{"$SET(msg, $NOEXEC(Hi $GET(name)))"}% sets the msg variable with raw formula Hi $GET(name)
- Example:
%CALC{"$SET(name, Tom) $EXEC($GET(msg))"}% executes content of msg variable and returns Hi Tom
- Example:
%CALC{"$SET(name, Jerry) $EXEC($GET(msg))"}% returns Hi Jerry
- Related:
$EVAL() , $GET() , $NOEXEC() , $SET()
EXISTS( topic ) -- check if topic exists
- Topic can be
TopicName or a Web.TopicName
- Syntax:
$EXISTS( topic )
- Example:
%CALC{"$EXISTS(WebHome)"}% returns 1
- Example:
%CALC{"$EXISTS(ThisDoesNotExist)"}% returns 0
| |
FIND( string, text, start ) -- find one string within another string
- Finds one text
string , within another text , and returns the number of the starting position of string , from the first character of text . This search is case sensitive and is not a regular expression search; use $SEARCH() for regular expression searching. Starting position is 1; a 0 is returned if nothing is matched.
| |
FORMAT( type, prec, number ) -- format a number to a certain type and precision | |
< < |
- Type can be COMMA for comma format, DOLLAR for Dollar format, NUMBER for number, and PERCENT for percent format
| > > |
- Type can be COMMA for comma format, DOLLAR for Dollar format, KB for Kilo Byte format, MB for Mega Byte format, KBMB for Kilo/Mega/Giga/Tera Byte auto-adjust format, NUMBER for number, and PERCENT for percent format
| |
- Syntax:
$FORMAT( type, prec, number )
- Example:
%CALC{"$FORMAT(COMMA, 2, 12345.6789)"}% returns 12,345.68
- Example:
%CALC{"$FORMAT(DOLLAR, 2, 12345.67)"}% returns $12,345.68
| |
> > |
- Example:
%CALC{"$FORMAT(KB, 2, 1234567)"}% returns 1205.63 KB
- Example:
%CALC{"$FORMAT(MB, 2, 1234567)"}% returns 1.18 MB
- Example:
%CALC{"$FORMAT(KBMB, 2, 1234567)"}% returns 1.18 MB
- Example:
%CALC{"$FORMAT(KBMB, 2, 1234567890)"}% returns 1.15 GB
| |
- Example:
%CALC{"$FORMAT(NUMBER, 1, 12345.67)"}% returns 12345.7
- Example:
%CALC{"$FORMAT(PERCENT, 1, 0.1234567)"}% returns 12.3%
- Related:
$ROUND()
| |
- Specify the variable name (alphanumeric characters and underscores). An empty string is returned if the variable does not exist. Use
$SET() to set a variable first. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables.
- Syntax:
$GET( name )
- Example:
%CALC{"$GET(my_total)"}% returns the value of the my_total variable
| |
< < | | > > | | |
IF( condition, value if true, value if 0 ) -- return a value based on a condition | |
- Convert the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list
- Syntax:
$LIST( range )
- Example:
%CALC{"$LIST($LEFT())"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
| |
< < |
- Related:
$AVERAGE() , $COUNTITEMS() , $COUNTSTR() , $DEF() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $MAX() , $MEDIAN() , $MIN() , $PRODUCT() , $SUM() , $SUMDAYS() , $SUMPRODUCT()
| > > |
- Related:
$AVERAGE() , $COUNTITEMS() , $COUNTSTR() , $DEF() , $LISTIF() , $LISTITEM() , $LISTJOIN() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $MAX() , $MEDIAN() , $MIN() , $PRODUCT() , $SUM() , $SUMDAYS() , $SUMPRODUCT()
| |
LISTIF( condition, list ) -- remove elements from a list that do not meet a condition | |
- Example:
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
| |
> > |
LISTJOIN( separator, list ) -- convert a list into a string
- By default, list items are separated by a comma and a space. Use this function to indicate a specific
separator string, which may include $comma for comma, $n for newline, and $sp for space.
- Syntax:
$LISTJOIN( separator, list )
- Example:
%CALC{"$LISTJOIN($n, Apple, Orange, Apple, Kiwi)"}% returns the four items separated by new lines
- Related:
$LIST() , $LISTSIZE()
| |
LISTMAP( formula, list ) -- evaluate and update each element of a list
- In the formula you can use
$item to indicate the element; $index to show the index of the list, starting at 1
| | LISTSIZE( list ) -- number of elements in a list
- Syntax:
$LISTSIZE( list )
- Example:
%CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
| |
< < | | > > |
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTJOIN() , $LISTMAP() , $LISTREVERSE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
| |
LISTSORT( list ) -- sort a list | | MAX( list ) - biggest value of a list or range of cells
- Syntax:
$MAX( list )
- Example: To find the biggest number to the left of the current cell, write:
%CALC{"$MAX($LEFT())"}%
| |
< < | | > > | | |
MEDIAN( list ) -- median of a list or range of cells
- Syntax:
$MEDIAN( list )
- Example:
%CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
| |
< < | | > > | | |
MIN( list ) -- smallest value of a list or range of cells
- Syntax:
$MIN( list )
- Example:
%CALC{"$MIN(15, 3, 28)"}% returns 3
| |
< < | | > > | | |
MOD( num, divisor ) -- reminder after dividing num by divisor
- Syntax:
$MOD( num, divisor )
- Example:
%CALC{"$MOD(7, 3)"}% returns 1
| |
< < | | > > |
NOEXEC( formula ) -- do not execute a spreadsheet formula
- Prevent a formula from getting executed. This is typically used to store a raw formula in a variable for later use as described in
$EXEC() .
- Syntax:
$NOEXEC( formula )
- Example:
%CALC{"$SET(msg, $NOEXEC(Hi $GET(name)))"}% sets the msg variable with the formula Hi $GET(name) without executing it
- Related:
$EVAL() , $EXEC() , $GET() , $SET()
| |
NOP( text ) -- no-operation | | | |
> > |
ODD( num ) -- test for odd number | |
OR( list ) -- logcial OR of a list
- Syntax:
$OR( list )
- Example:
%CALC{"$OR(1, 0, 1)"}% returns 1
- Related:
$AND() , $IF() , $NOT()
| |
> > |
PERCENTILE( num, list ) -- percentile of a list or range of cells
- Calculates the num-th percentile, useful to establish a threshold of acceptance. num is the percentile value, range 0..100
- Syntax:
$PERCENTILE( num, list )
- Example:
%CALC{"$PERCENTILE(75, 400, 200, 500, 100, 300)"}% returns 450
- Related:
$LIST() , $MAX() , $MEDIAN() , $MIN()
| |
PRODUCT( list ) -- product of a list or range of cells | |
| |
< < | PROPER( text ) -- properly capitalize trxt | > > | PROPER( text ) -- properly capitalize text | |
- Capitalize letters that follow any character other than a letter; convert all other letters to lowercase letters
- Syntax:
$PROPER( text )
- Example:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
| | 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
- 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
| > > |
- 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
| |
| |
SET( name, value ) -- set a variable for later use | |
< < |
- Specify the variable name (alphanumeric characters and underscores) and the value. The value may contain a formula; formulas are evaluated before the variable assignment. This function returns no output. Use
$GET() to retrieve variables. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables
| > > |
- Specify the variable name (alphanumeric characters and underscores) and the value. The value may contain a formula; formulae are evaluated before the variable assignment; see
$NOEXEC() if you want to prevent that. This function returns no output. Use $GET() to retrieve variables. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables and also included topics
| |
- Syntax:
$SET( name, value )
- Example:
%CALC{"$SET(my_total, $SUM($ABOVE()))"}% sets the my_total variable to the sum of all table cells located above the current cell and returns an empty string
| |
< < | | > > | | |
SETM( name, formula ) -- update an existing variable based on a formula | |
- Returns -1 if
num is negative, 0 if zero, or 1 if positive
- Syntax:
$SIGN( num )
- Example:
%CALC{"$SIGN(-12.5)"}% returns -1
| |
< < | | > > | | |
SUBSTITUTE( text, old, new, instance, option ) -- substitute text | |
SUMPRODUCT( list, list ) -- scalar product on ranges of cells
- Syntax:
$SUMPRODUCT( list, list, list... )
| |
< < |
- Example:
%CALC{"$SUM(R2:C1..R4:C1, R2:C5..R4:C5)"}% evaluates and returns the result of ($T(R2:C1) * $T(R2:C5) + $T(R3:C1) * $T(R3:C5) + $T(R4:C1) * $T(R4:C5))
| > > |
- Example:
%CALC{"$SUMPRODUCT(R2:C1..R4:C1, R2:C5..R4:C5)"}% evaluates and returns the result of ($T(R2:C1) * $T(R2:C5) + $T(R3:C1) * $T(R3:C5) + $T(R4:C1) * $T(R4:C5))
| |
| | TIMEADD( serial, value, unit ) -- add a value to a serialized date
- The unit is seconds if not specified; unit can be
second , minute , hour , day , week , month , year . Note: An approximation is used for month and year calculations
- Syntax:
$TIMEADD( serial, value, unit )
| |
< < |
- Example:
%CALC{"$TIMEADD($TIME(), 2, week)"}%
- Related:
$() , $() returns the serialized date two weeks from now
| > > |
- Example:
%CALC{"$TIMEADD($TIME(), 2, week)"}% returns the serialized date two weeks from now
| |
| |
- Debug plugin: (See output in
data/debug.txt )
| |
< < |
- Do not handle
%CALC{}% tag in included topic while including topic: (default: 1)
| > > |
- Do not handle
%CALC{}% variable in included topic while including topic: (default: 1)
| |
| |
data/TWiki/SpreadSheetPlugin.txt | Plugin topic |
data/TWiki/SpreadSheetPlugin.txt,v | Plugin topic repository |
lib/TWiki/Plugins/SpreadSheetPlugin.pm | Plugin Perl module |
| |
> > |
- (Dakar) 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
| |
< < |
Plugin Version: | 17 Jul 2004 |
| > > |
Plugin Version: | 17 Jun 2005 (1.018) |
| |
Change History: | <-- specify latest version first --> |
| |
> > |
17 Jun 2005: | Added $NOEXEC(), $EXEC() |
25 Mar 2005: | Fixed evaluation bug when using SpeedyCGI accelerator; code refactor to load module only when needed, contributed by TWiki:Main/CrawfordCurrie |
24 Oct 2004: | Added $EXISTS(), contributed by TWiki:Main/RodrigoChandia; added $PERCENTILE() |
18 Oct 2004: | Added $LISTJOIN() |
26 Sep 2004: | Added $FORMAT(KB), $FORMAT(MB), contributed by TWiki:Main/ArthurClemens; added $FORMAT(KBMB), $EVEN(), $ODD() |
| |
17 Jul 2004: | Added $WORKINGDAYS(), contributed by TWiki:Main/CrawfordCurrie |
24 May 2004: | Refactored documentation (no code changes) |
03 Apr 2004: | Added $ABS(), $LISTIF(); fixed $VALUE() to remove leading zeros; changed $FIND() and $SEARCH() to return 0 instead of empty string if no match |
| |
| |
< < |
19 Apr 2003: | Added $COUNTSTR(), $EXACT(), $IF(), $ROUND(), $TRIM(); added $FORMAT(), contributed by TWiki:Main/JimStraus; support % modulus operator in $EVAL, $INT, and $ROUND; fixed bug in $DEF |
| > > |
19 Apr 2003: | Added $COUNTSTR(), $EXACT(), $IF(), $ROUND(), $TRIM(); added $FORMAT(), contributed by TWiki:Main/JimStraus; support % modulus operator in $EVAL(), $INT(), and $ROUND(); fixed bug in $DEF() |
| |
07 Jun 2002: | Added $DEF(), contributed by TWiki:Main/MartinFuzzey; allow values with HTML formatting like <u>102</u> , suggested by TWiki:Main/GladeDiviney; added SKIPINCLUDE setting |
12 Mar 2002: | Support for multiple functions per nesting level |
15 Jan 2002: | Added $CHAR(), $CODE() and $LENGTH() |
12 Nov 2001: | Added $RIGHT() |
12 Aug 2001: | Fixed bug of disappearing multi-column cells |
| |
< < |
19 Jul 2001: | Fixed incorrect $SUM calculation of cell with value 0 |
| > > |
19 Jul 2001: | Fixed incorrect $SUM() calculation of cell with value 0 |
| |
14 Jul 2001: | Changed to plug & play |
| |
< < |
01 Jun 2001: | Fixed insecure dependencies for $MIN and $MAX |
16 Apr 2001: | Fixed div by 0 bug in $AVERAGE |
17 Mar 2001: | Initial version |
| > > |
01 Jun 2001: | Fixed insecure dependencies for $MIN() and $MAX() |
16 Apr 2001: | Fixed div by 0 bug in $AVERAGE() |
17 Mar 2001: | Initial version with $ABOVE(), $AVERAGE(), $COLUMN(), $COUNTITEMS(), $EVAL(), $INT(), $LEFT(), $LOWER(), $MAX(), $MIN(), $ROW(), $SUM(), $T(), $UPPER() |
| |
| | Related Topics: TWikiPreferences, TWikiPlugins | |
< < | -- TWiki:Main/PeterThoeny - 17 Jul 2004 | > > | -- TWiki:Main/PeterThoeny - 17 Jun 2005 | | |
|