SpreadSheetPlugin 14 - 19 Dec 2006 - Main.PeterThoeny
|
| TWiki Spreadsheet Plugin
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. | |
- 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() , $LISTJOIN() , $LISTMAP() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $MAX() , $MEDIAN() , $MIN() , $PRODUCT() , $SUM() , $SUMDAYS() , $SUMPRODUCT()
| > > |
- Related:
$AVERAGE() , $COUNTITEMS() , $COUNTSTR() , $DEF() , $LISTIF() , $LISTITEM() , $LISTJOIN() , $LISTMAP() , $LISTRAND() , $LISTREVERSE() , $LISTSHUFFLE() , $LISTSIZE() , $LISTSORT() , $LISTTRUNCATE() , $LISTUNIQUE() , $MAX() , $MEDIAN() , $MIN() , $PRODUCT() , $SUM() , $SUMDAYS() , $SUMPRODUCT()
| |
LISTIF( condition, list ) -- remove elements from a list that do not meet a condition | |
- Syntax:
$LISTITEM( index, list )
- Example:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
- Example:
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
| |
< < | | > > |
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTMAP() , $LISTRAND() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
| |
LISTJOIN( separator, list ) -- convert a list into a string | |
- Example:
%CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTREVERSE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
| |
> > |
LISTRAND( list ) -- get one random element of a list
- Syntax:
$LISTRAND( list )
- Example:
%CALC{"$LISTRRAND(Apple, Orange, Apple, Kiwi)"}% returns one of the four elements
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTSHUFFLE() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $RAND() , $SUM()
| |
LISTREVERSE( list ) -- opposite order of a list
- Syntax:
$LISTREVERSE( list )
| | 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()
| > > |
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTJOIN() , $LISTMAP() , $LISTREVERSE() , $LISTSORT() , $LISTTRUNCATE() , $LISTUNIQUE() , $SUM()
LISTSHUFFLE( list ) -- shuffle element of a list in random order
- Syntax:
$LISTSHUFFLE( list )
- Example:
%CALC{"$LISTSHUFFLE(Apple, Orange, Apple, Kiwi)"}% returns the four elements in random order
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTRAND() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $RAND() , $SUM()
| |
LISTSORT( list ) -- sort a list
- Sorts a list in ASCII order, or numerically if all elements are numeric
- Syntax:
$LISTSORT( list )
- Example:
%CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
| |
< < | | > > |
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTREVERSE() , $LISTSHUFFLE() , $LISTSIZE() , $LISTUNIQUE() , $SUM()
LISTTRUNCATE( size, list ) -- truncate list to size
- Specify the desired size of the list; use a negative number to count from the end of the list
- Syntax:
$LISTTRUNCATE( size, list )
- Example:
%CALC{"$LISTTRUNCATE(2, Apple, Orange, Kiwi)"}% returns Apple, Orange
- Related:
$COUNTITEMS() , $COUNTSTR() , $LIST() , $LISTIF() , $LISTITEM() , $LISTMAP() , $LISTSIZE() , $LISTSORT() , $LISTUNIQUE() , $SUM()
| |
LISTUNIQUE( list ) -- remove all duplicates from a list | | RAND( max ) -- random number
- Random number, evenly distributed between 0 and
max , or 0 and 1 if max is not specified
- Syntax:
$RAND( max )
| |
< < | | > > | | | | |
< < | REPEAT(text) -- repeat text a number of times | > > | REPEAT( text, num ) -- repeat text a number of times
- Syntax:
$REPEAT( text, num )
| |
- Example:
%CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
| | | |
> > | FAQ
Can I use CALC in a formatted search?
Specifically, how can I output some conditional text in a FormattedSearch?
You need to escape the CALC so that it executes once per search hit. This can be done by escaping the % signs of %CALC{...}% with $percnt . For example, to execute $IF($EXACT($formfield(Tested), Yes), %PUBURL%/%TWIKIWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%TWIKIWEB%/TWikiDocGraphics/choice-no.gif) in the format="" parameter, write this:
%SEARCH{ .... format="| $topic | $percntCALC{$IF($EXACT($formfield(Tested), Yes), %PUBURL%/%TWIKIWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%TWIKIWEB%/TWikiDocGraphics/choice-no.gif)}$percnt |" }%
How can I easily repeat a formula in a table?
To repeat the same formula in all cells of a table row define the formula once in a preferences setting and use that in the CALC. The preferences setting can be hidden in HTML comments. Example:
<!--
* Set MYFORMULA = $EVAL($SUBSTITUTE(...etc...))
-->
| A | 1 | %CALC{%MYFORMULA%}% |
| B | 2 | %CALC{%MYFORMULA%}% |
| C | 3 | %CALC{%MYFORMULA%}% |
| | Bug Tracking Example
| | a plugin setting write %<plugin>_<setting>% , i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
| |
< < |
-
- Set SHORTDESCRIPTION = Add spreadsheet calculation like
"$SUM( $ABOVE() )" to tables located in TWiki topics.
| > > |
-
- Set SHORTDESCRIPTION = Add spreadsheet calculation like
"$SUM( $ABOVE() )" to TWiki tables and other topic text
| |
- Debug plugin: (See output in
data/debug.txt )
| |
| |
< < |
Plugin Version: | 13 May 2006 (10197) |
| > > |
Plugin Version: | 18 Dec 2006 (r12315) |
| |
Change History: | <-- specify latest version first --> |
| |
> > |
18 Dec 2006: | Added $LISTRAND(), $LISTSHUFFLE(), $LISTTRUNCATE(); fixed spurious newline at end of topic, contributed by TWiki:Main/MichaelDaum |
10 Oct 2006: | Enhanced documentation |
| |
13 May 2006: | Added $SETIFEMPTY(); fixes in documentation |
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 |
| | Related Topics: TWikiPreferences, TWikiPlugins | |
< < | -- TWiki:Main/PeterThoeny - 13 May 2006 | > > | -- TWiki:Main/PeterThoeny - 18 Dec 2006 | | |
|
Revision 14 | r14 - 19 Dec 2006 - 06:30:52 - PeterThoeny? |
Revision 13 | r13 - 13 May 2006 - 19:33:17 - PeterThoeny? |
|
|
This site is powered by the TWiki collaboration platform. All material on this collaboration platform is the property of the contributing authors. All material marked as authored by Eben Moglen is available under the license terms CC-BY-SA version 4.
|
|