Difference: SpreadSheetPlugin (1 vs. 30)

Revision 302015-06-07 - TWikiContributor

Line: 1 to 1
Changed:
<
<
>
>
 
    Page contents    
Changed:
<
<
>
>
 

TWiki Spreadsheet Plugin

Revision 292014-09-23 - TWikiContributor

Line: 1 to 1
 
    Page contents    
Line: 68 to 68
 
  • Functions are evaluated from left to right, and from inside to outside if nested
  • A function parameter can be text, a mathematical formula, a cell address, or a range of cell addresses
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, such as %CALCULATE{$SUM( 3, 5, 7 )}%
Changed:
<
<
  • A parameter representing a string can optionally be enclosed in triple quotes; quotes are required if the string contains commas or parenthesis, such as %CALCULATE{$SUBSTITUTE('''Good, early morning''', morning, day)}%
>
>
  • A parameter representing a string can optionally be enclosed in triple quotes; quotes are required if the string contains commas, parenthesis or newlines, such as %CALCULATE{$SUBSTITUTE('''Good, early morning''', morning, day)}%
  • The %CALCULATE{...}% variable may span multiple lines, which is useful to indent nested functions. In case the variable contains newlines, all white space around functions and function parameters is removed. Sample nested formula:
    %CALCULATE{
      $LISTJOIN(
        $n,
        $LISTEACH(
          | $index | $item |,
          one, two, three
        )
      )
    }%
 
  • A table cell can be addressed as R1:C1. Table address matrix:
    R1:C1 R1:C2 R1:C3 R1:C4
    R2:C1 R2:C2 R2:C3 R2:C4
Line: 105 to 115
 
Added:
>
>

ADDLIST( name, list ) -- append a list to a list variable

  • Specify the variable name (alphanumeric characters and underscores) and the list to add. If the named list does not exist it will be created. Useful in a FormattedSearch to add items to a list. This function returns no output. Use $GETLIST() to retrieve a list variable.
  • Syntax: $ADDLIST( name, list )
  • Example:
    %CALCULATE{$SETLIST(nums, 0, 1, 2, 3)}% sets the nums variable to 0, 1, 2, 3
    %CALCULATE{$ADDLIST(nums, 4, 5, 6, 7)}% adds 4, 5, 6, 7 to the nums variable
    %CALCULATE{$GETLIST(nums)}% returns 0, 1, 2, 3, 4, 5, 6, 7
  • Example formatted search:
    format="$percntCALCULATE{$ADDLIST(topics, $topic)}$percnt" in each search hit, adds the topic name to the topics list variable
  • Related: $GETLIST(), $SET(), $SETHASH(), $SETLIST()
 

AND( list ) -- logical AND of a list

  • Syntax: $AND( list )
Line: 292 to 314
 

FORMAT( type, precision, number ) -- format a number to a certain type and precision

  • Supported type:
    • COMMA for comma format, such as 12,345.68
Added:
>
>
    • CURRENCY for currency format, such as €12,345.68
      • Negative numbers are shown in parenthesis, such as (€6,789.00) for -6789
      • The currency symbol is taken from the CURRENCYSYMBOL preferences setting, such as US$ or $ for Dollar, &#8364; for Euro, &#165; for Yen, default $
 
    • DOLLAR for Dollar format, such as $12,345.68
Added:
>
>
      • Negative numbers are shown in parenthesis, such as ($6,789.00) for -6789
 
    • KB for Kilo Byte format, such as 1205.63 KB
    • MB for Mega Byte format, such as 1.18 MB
    • KBMB for Kilo/Mega/Giga/Tera Byte auto-adjust format
Line: 301 to 327
 
  • The precision indicates the the number of digits after the dot
  • Syntax: $FORMAT( type, prec, number )
  • Example: %CALCULATE{$FORMAT(COMMA, 2, 12345.6789)}% returns 12,345.68
Added:
>
>
  • Example: %CALCULATE{$FORMAT(CURRENCY, 2, 12345.6789)}% returns $12,345.68
 
  • Example: %CALCULATE{$FORMAT(DOLLAR, 2, 12345.6789)}% returns $12,345.68
  • Example: %CALCULATE{$FORMAT(KB, 2, 1234567)}% returns 1205.63 KB
  • Example: %CALCULATE{$FORMAT(MB, 2, 1234567)}% returns 1.18 MB
Line: 369 to 396
 
  • 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: %CALCULATE{$GET(my_total)}% returns the value of the my_total variable
Changed:
<
<
>
>
 

GETHASH( name, key ) -- get the value of a previously set hash key

  • Specify the hash name and key; allowed characters for the hash name are alphanumeric characters, underscores and period. An empty string is returned if the hash key does not exist. Use $SETHASH() or $LIST2HASH() to set a hash. If the key is omitted, a list of all keys of the named hash is returned. If no parameters are specified, a list of all hash names is returned.
  • Syntax: $GETHASH( name, key )
  • Examples:
    %CALCULATE{$SETHASH(age, Jane, 26)}%
    %CALCULATE{$SETHASH(age, Tim, 27)}%
    %CALCULATE{$GETHASH(age, Jane)}% returns 26
    %CALCULATE{$GETHASH(age)}% returns Jane, Tim
    %CALCULATE{$GETHASH()}% returns age
Changed:
<
<
>
>

GETLIST( name ) -- get the list from a list variable

  • Specify the variable name (alphanumeric characters and underscores). An empty list is returned if the variable does not exist. Use $SETLIST() or $ADDLIST() to set a variable.
  • Syntax: $GETLIST( name )
  • Example: %CALCULATE{$GETLIST(nums)}% returns the value of the nums variable
  • Related: $ADDLIST(), $GET(), $GETHASH(), $SETLIST(), SetGetPlugin
 

HASH2LIST( name, format ) -- convert a hash to a list

Line: 787 to 821
 

SET( name, value ) -- set a variable for later use

Changed:
<
<
  • 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 across included topics
>
>
  • 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 across included topics. If the value is omitted, the named variable is deleted.
 
  • 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
Changed:
<
<
>
>
 

SETHASH( name, key, value ) -- set a hash value for later use, or delete a hash

Line: 801 to 835
 
  • Example: %CALCULATE{$SETHASH(age, Jane)}% deletes key Jane of hash named age
  • Example: %CALCULATE{$SETHASH(age)}% deletes hash named age
  • Example: %CALCULATE{$SETHASH()}% deletes all hashes
Changed:
<
<
>
>
 

SETIFEMPTY( name, value ) -- set a variable only if empty

Line: 810 to 844
 
  • Example: %CALCULATE{$SETIFEMPTY(result, default)}% sets the result variable to default if the variable is empty or 0; in any case an empty string is returned
  • Related: $GET(), $SET(), $SETHASH(), $SETMHASH()
Added:
>
>

SETLIST( name, list ) -- save a list for later use

  • Specify the variable name (alphanumeric characters and underscores) and the list. This function returns no output. Use $GETLIST() to retrieve a list variable. Use $ADDLIST() to add a list to an existing variable. If no list is specified, the named variable is deleted.
  • Syntax: $SETLIST( name, list )
  • Example: %CALCULATE{$SETLIST(octals, 0, 1, 2, 3, 4, 5, 6, 7)}% sets the octals variable to 0, 1, 2, 3, 4, 5, 6, 7
  • Example: %CALCULATE{$SETLIST(octals)}% deletes the octals variable
  • Related: $ADDLIST(), $GETLIST(), $SET(), $SETHASH(), SetGetPlugin
 

SETM( name, formula ) -- modify an existing variable based on a formula

  • Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables
Line: 1030 to 1072
  "form.name='FeatureForm'" type="query" nonoise="on"
Changed:
<
<
format="$percntCALCULATE{$SETHASH(status, $topic, $formfield(Status))$SETHASH(summary, $topic, $summary(entityencode))$SETHASH(date, $topic, $date)}$percnt"
>
>
format="$percntCALCULATE{$SETHASH(status, $topic, $formfield(Status))$SETHASH(summary, $topic, '''$summary''')$SETHASH(date, $topic, '''$date''')}$percnt"
 }%

Proposed Features

Feature Updated
Changed:
<
<
>
>
 

Accepted Features

Feature Updated
Changed:
<
<
>
>
 

First we search all features and store the status, summary and date in hashes, using the topic name as the key. Then we build a table that shows all proposed features, followed by a table showing all accepted features. Reading the CALCULATE formula from inside out:

Line: 1115 to 1185
 
  • Do not handle %CALC{}% variable in included topic while including topic: (default: 1) (See note CALC in Included Topics)
    • Set SKIPINCLUDE = 1
Added:
>
>
  • Currency symbol. Specify US$ or $ for Dollar, &#8364; for Euro, &#165; for Yen:
    • Set CURRENCYSYMBOL = $
 
  • WikiWords to exclude from being spaced out by the $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
    • Set DONTSPACE = CodeWarrior, MacDonald, McIntosh, RedHat, SuSE
Line: 1154 to 1227
 
Plugin Author: TWiki:Main.PeterThoeny
Changed:
<
<
Copyright: © 2001-2013 Peter Thoeny, TWiki.org
© 2008-2013 TWiki:TWiki.TWikiContributor
© 2013 Wave Systems Corp.
>
>
Copyright: © 2001-2014 Peter Thoeny, TWiki.org
© 2008-2014 TWiki:TWiki.TWikiContributor
© 2014 Wave Systems Corp.
 
Sponsor: Wave Systems Corp. for hash functions
License: GPL (GNU General Public License)
Changed:
<
<
Plugin Version: 2013-10-10
>
>
Plugin Version: 2014-09-23
 
<--/twistyPlugin twikiMakeVisibleInline-->
Added:
>
>
2014-09-23: TWikibug:Item7553: Allow newlines and indent around functions and function parameters
2014-09-22: TWikibug:Item7552: Allow newlines in triple-quoted strings
2014-03-04: TWikibug:Item7445: Add FORMAT(CURRENY, ...) with support for currency symbol
2014-01-22: TWikibug:Item7419: Add ADDLIST(), GETLIST(), SETLIST()
2014-01-22: TWikibug:Item7418: Fix VALUE function bug with incorrect exponential number; ability to delete SET variable; do not strip trailing spaces in SETIFEMPTY
 
2013-10-10: TWikibug:Item7154: Doc update: Put TOC on top right for easy reference
2013-09-14: TWikibug:Item7299: Fix plural of month to months in FORMATTIMEDIFF
Changed:
<
<
2013-08-21: TWikibug:Item7322: TRANSLATE supporting double quote and apostrophe-quote (single quote) excape tokens
>
>
2013-08-21: TWikibug:Item7322: TRANSLATE supporting double quote and apostrophe-quote (single quote) escape tokens
 
2013-07-18: TWikibug:Item7299: Add short and compact format to FORMATTIMEDIFF
2013-06-20: TWikibug:Item7154: Fix encoding of URL parameter in the interactive example so that $IF(1>2, true, false) works properly
2013-05-21: TWikibug:Item7154: Small doc fixes

Revision 282013-10-10 - TWikiContributor

Line: 1 to 1
Added:
>
>
    Page contents    
 

TWiki Spreadsheet Plugin

Changed:
<
<
This plugin adds spreadsheet capabilities to TWiki topics. Functions such as %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 function evaluation capability, not just classic spreadsheet functions. The plugin currently has
>
>
This plugin adds spreadsheet capabilities to TWiki topics. Functions such as %CALCULATE{$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 function evaluation capability, not just classic spreadsheet functions. The plugin currently has
 

Revision 272013-01-10 - TWikiContributor

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Revision 262012-11-12 - TWikiContributor

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Revision 252012-10-06 - TWikiContributor

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Changed:
<
<
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.
>
>
This plugin adds spreadsheet capabilities to TWiki topics. Functions such as %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 function evaluation capability, not just classic spreadsheet functions. The plugin currently has
<--                                                                                                                               -->
630 functions.
 
Example:
Line: 18 to 27
 
South 240
Europe 610
Asia 220
Changed:
<
<
Total: 0
>
>
Total: 0
 
      Interactive example:
Changed:
<
<
>
>
 
Changed:
<
<
Formula: %CALC{"TWikiGuest)" class="twikiInputField" />"}%
>
>
Formula:
 %CALC{TWikiGuest)" class="twikiInputField" />}%
 
Changed:
<
<
Result:     TWiki Guest
>
>
Result:   TWiki Guest
 
Changed:
<
<
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 is not enabled.)
 

On this page:

Syntax Rules

Changed:
<
<
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.
>
>
This plugin handles the %CALC{...}% and %CALCULATE{...}% variables. Built-in functions found between the quotes are evaluated as follows:
 
  • Built-in function are of format $FUNCNAME(parameter)
Changed:
<
<
  • Functions may be nested, such as %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
>
>
  • Functions may be nested, such as %CALC{$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )}%
 
  • Functions are evaluated from left to right, and from inside to outside if nested
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
Changed:
<
<
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, such as %CALC{"$SUM( 3, 5, 7 )"}%
>
>
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, such as %CALC{$SUM( 3, 5, 7 )}%
 
  • A table cell can be addressed as R1:C1. Table address matrix:
    R1:C1 R1:C2 R1:C3 R1:C4
    R2:C1 R2:C2 R2:C3 R2:C4
  • A table cell range is defined by two cell addresses separated by "..", e.g. "row 1 through 20, column 3" is: R1:C3..R20:C3
Changed:
<
<
  • Lists can refer to values and/or table cell ranges, such as %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
  • Formulae can be placed in a FormattedSearch, but the CALC needs to be escaped. Learn how to use a CALC in a formatted search
  • Plain text can be added, such as %CALC{"Total: $SUM($ABOVE()) kg"}%
>
>
  • Lists can refer to values and/or table cell ranges, such as %CALC{$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )}%
  • Functions can only reference cells in the current or preceeding row of the current table; they may not reference cells below the current table row
  • Functions can also be placed outside of tables; they can reference cells in the preceeding table
  • Functions can be placed in a FormattedSearch, but the CALC needs to be escaped. Learn how to use a CALC in a formatted search
  • Plain text can be added, such as %CALC{Total: $SUM($ABOVE()) kg}%
 
Changed:
<
<

Built-in Functions

>
>

Use CALC or CALCULATE

 
Changed:
<
<
Conventions for Syntax:
>
>
Table Use %CALC{...}% in table cells:
The CALC variable handles all functions, but it gets handled with delay compared to other TWikiVariables: It gets executed after internal variables and plugin variables that use the register tag handler. You may get unexpected results if you nest CALC inside other variables (such as %INCLUDE{%CALC{...}%}%) because it does not get evaluated inside-out & left-to-right like ordinary TWiki variables.

Index list Use %CALCULATE{...}% outside tables:
The CALCULATE variable is handled inside-out & left-to-right like ordinary TWiki variables, but it does not support functions that refer to table cells, such as $LEFT() or $T().

Built-in Spreadsheet Plugin Functions

The plugin currently has 756 functions. Convention for parameters:

 
  • Required parameters are indicated in ( bold )
  • Optional parameters are indicated in ( bold italic )

ABOVE( ) -- address range of cells above the current cell

  • Syntax: $ABOVE( )
Changed:
<
<
  • Example: %CALC{"$SUM($ABOVE())"}% returns the sum of cells above the current cell
>
>
  • Example: %CALC{$SUM($ABOVE())}% returns the sum of cells above the current cell
 

ABS( num ) -- absolute value of a number

  • Syntax: $ABS( num )
Changed:
<
<
>
>
 

AND( list ) -- logical AND of a list

  • Syntax: $AND( list )
Changed:
<
<
  • Example: %CALC{"$AND(1, 0, 1)"}% returns 0
>
>
  • Example: %CALC{$AND(1, 0, 1)}% returns 0
 

AVERAGE( list ) -- average of a list or a range of cells

  • Syntax: $AVERAGE( list )
Changed:
<
<
  • Example: %CALC{"$AVERAGE(R2:C5..R$ROW(-1):C5)"}% returns the average of column 5, excluding the title row
>
>
  • Example: %CALC{$AVERAGE(R2:C5..R$ROW(-1):C5)}% returns the average of column 5, excluding the title row
 

BITXOR( text ) -- bit-wise XOR of text

  • Each bit of each character of text is flipped, useful to obfuscate text. Bit-XORing text twice will restore the original text.
  • Syntax: $BITXOR( text )
Changed:
<
<
  • Example: %CALC{"$BITXOR(A123)"}% returns ŸÎÍÌ
  • Example: %CALC{"$BITXOR($BITXOR(anything))"}% returns anything
>
>
  • Example: %CALC{$BITXOR(A123)}% returns ŸÎÍÌ
  • Example: %CALC{$BITXOR($BITXOR(anything))}% returns anything
 

Line: 99 to 116
 
  • The ceiling(x) is the smallest integer not less than x
  • Use $INT() to truncate a number towards zero; use $FLOOR() to get the largest previous integer
  • Syntax: $CEILING( num )
Changed:
<
<
  • Example: %CALC{"$CEILING(5.4)"}% returns 6
  • Example: %CALC{"$CEILING(-5.4)"}% returns -5
>
>
  • Example: %CALC{$CEILING(5.4)}% returns 6
  • Example: %CALC{$CEILING(-5.4)}% returns -5
 

CHAR( number ) -- ASCII character represented by number

  • Syntax: $CHAR( number )
Changed:
<
<
  • Example: Example: %CALC{"$CHAR(97)"}% returns a
>
>
  • Example: Example: %CALC{$CHAR(97)}% returns a
 

CODE( text ) -- ASCII numeric value of character

  • The ASCII numeric value of the first character in text
  • Syntax: $CODE( text )
Changed:
<
<
  • Example: %CALC{"$CODE(abc)"}% returns 97
>
>
  • Example: %CALC{$CODE(abc)}% returns 97
 

COLUMN( offset ) -- current column number

  • The current table column number with an optional offset
  • Syntax: $COLUMN( offset )
Changed:
<
<
  • Example: %CALC{"$COLUMN()"}% returns 2 for the second column
>
>
  • Example: %CALC{$COLUMN()}% returns 2 for the second column
 

COUNTITEMS( list ) -- count individual items in a list

  • Syntax: $COUNTITEMS( list )
Changed:
<
<
  • Example: %CALC{"$COUNTITEMS($ABOVE())"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
>
>
  • Example: %CALC{$COUNTITEMS($ABOVE())}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
 

COUNTSTR( list, str ) -- count the number of cells in a list equal to a given string

  • Count the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list
  • Syntax: $COUNTSTR( list, str )
Changed:
<
<
  • Example: %CALC{"$COUNTSTR($ABOVE())"}% counts the number of non empty cells above the current cell
  • Example: %CALC{"$COUNTSTR($ABOVE(), DONE)"}% counts the number of cells equal to DONE
>
>
  • Example: %CALC{$COUNTSTR($ABOVE())}% counts the number of non empty cells above the current cell
  • Example: %CALC{$COUNTSTR($ABOVE(), DONE)}% counts the number of cells equal to DONE
 

DEF( list ) -- find first non-empty list item or cell

  • Returns the first list item or cell reference that is not empty
  • Syntax: $DEF( list )
Changed:
<
<
  • Example: %CALC{"$DEF(R1:C1..R1:C3)"}%
>
>
  • Example: %CALC{$DEF(R1:C1..R1:C3)}%
 

EMPTY( text ) -- test for empty text

  • Returns 1 if text is empty, or 0 if not
  • Syntax: $EMPTY( text )
Changed:
<
<
  • Example: %CALC{"$EMPTY(foo)"}% returns 0
  • Example: %CALC{"$EMPTY()"}% returns 1
  • Example: %CALC{"$EMPTY($TRIM( ))"}% returns 1
  • Related: $EXACT(), $IF(), $TRIM(), $WHILE()
>
>
 

EVAL( formula ) -- evaluate a simple mathematical formula

  • Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
  • Numbers may be decimal integers (1234), binary integers (0b1110011), octal integers (01234), hexadecimal integers (0x1234) or of exponential notation (12.34e-56)
  • Syntax: $EVAL( formula )
Changed:
<
<
  • Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
>
>
  • Example: %CALC{$EVAL( (5 * 3) / 2 + 1.1 )}% returns 8.6
 

EVEN( num ) -- test for even number

  • Syntax: $EVEN( num )
Changed:
<
<
>
>
 

EXACT( text1, text2 ) -- compare two text strings

  • Compares two text strings and returns 1 if they are exactly the same, or 0 if not
  • Syntax: $EXACT( text1, text2 )
Changed:
<
<
  • Example: %CALC{"$EXACT(foo, Foo)"}% returns 0
  • Example: %CALC{"$EXACT(foo, $LOWER(Foo))"}% returns 1
  • Related: $EMPTY(), $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 )
Changed:
<
<
  • 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
>
>
  • 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
 

EXISTS( topic ) -- check if topic exists

  • Topic can be TopicName or a Web.TopicName. Current web is used if web is not specified.
  • Syntax: $EXISTS( topic )
Changed:
<
<
  • Example: %CALC{"$EXISTS(WebHome)"}% returns 1
  • Example: %CALC{"$EXISTS(ThisDoesNotExist)"}% returns 0
  • Related: $EXACT(), $IF(), $TRIM()
>
>
 

EXP( num ) -- exponent (e) raised to the power of a number

  • EXP is the inverse of the LN function
  • Syntax: $EXP( num )
Changed:
<
<
  • Example: %CALC{"$EXP(1)"}% returns 2.71828182845905
>
>
  • Example: %CALC{$EXP(1)}% returns 2.71828182845905
 
Added:
>
>

FILTER( expression, text ) -- filter out characters from text

  • Remove characters from a text string. The filter is applied multiple times.
  • The expression can be a sequence of characters or a RegularExpression. Use tokens in the expression if needed: $comma for comma, $sp for space. The text may contain commas.
  • Syntax: $FILTER( chars, text )
  • Example: %CALC{$FILTER(f, fluffy)}% returns luy - filter out a character multiple times
  • Example: %CALC{$FILTER(an Franc, San Francisco)}% returns Sisco - cut a string
  • Example: %CALC{$FILTER($sp, Cat and Mouse)}% returns CatandMouse - remove all spaces
  • Example: %CALC{$FILTER([^0-9], Project-ID-1234)}% returns 1234 - filter in digits, e.g. keep only digits
  • Example: %CALC{$FILTER([^a-zA-Z0-9 ], Stupid mistake*%@^! Fixed)}% returns Stupid mistake Fixed - keep only alphanumeric characters and spaces
  • Example: %CALC{$FILTER([^a-zA-Z0-9], $PROPER(an EXELLENT idea.))}% returns AnExcellentIdea - turn a string into a WikiWord topic name
  • Related: $FIND(), $INSERTSTRING(), $LEFTSTRING(), $PROPER(), $REPLACE(), $RIGHTSTRING(), $SEARCH(), $SUBSTITUTE(), $SUBSTRING(), $TRANSLATE(), $TRIM()
 

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.
  • Syntax: $FIND( string, text, start )
Changed:
<
<
>
>
 

FLOOR( num ) -- return the largest integer preceding a number

  • The floor(x) is the largest integer not greater than x
  • Use $INT() to truncate a number towards zero; use $CEILING() to get the smallest following integer
  • Syntax: $FLOOR( num )
Changed:
<
<
  • Example: %CALC{"$FLOOR(5.4)"}% returns 5
  • Example: %CALC{"$FLOOR(-5.4)"}% returns -6
>
>
  • Example: %CALC{$FLOOR(5.4)}% returns 5
  • Example: %CALC{$FLOOR(-5.4)}% returns -6
 

Line: 229 to 259
 
    • PERCENT for percent format, such as 12.3%
  • The precision indicates the the number of digits after the dot
  • Syntax: $FORMAT( type, prec, number )
Changed:
<
<
  • 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%
>
>
  • 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%
 

FORMATGMTIME( serial, text ) -- convert a serialized date into a GMT date string

  • The date string represents the time in Greenwich time zone. Same variable expansion as in $FORMATTIME().
  • Syntax: $FORMATGMTIME( serial, text )
Changed:
<
<
  • Example: %CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
>
>
  • Example: %CALC{$FORMATGMTIME(1041379200, $day $mon $year)}% returns 01 Jan 2003
 

Line: 272 to 302
 
      • $isoweek($year-W$wk) - year-week ISO 8601 week number, such as 2009-W53 for 2010-01-03
  • Date is assumed to be server time; add GMT to text to indicate Greenwich time zone, or use $FORMATGMTIME().
  • Syntax: $FORMATTIME( serial, text )
Changed:
<
<
  • Example: %CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
>
>
  • Example: %CALC{$FORMATTIME(0, $year/$month/$day GMT)}% returns 1970/01/01 GMT
 

Line: 281 to 311
 
  • The input unit can be second, minute, hour, day, month, year. Note: An approximation is used for month and year calculations.
  • The precision indicates the number of output units to use
  • Syntax: $FORMATTIMEDIFF( unit, precision, time )
Changed:
<
<
  • Example: %CALC{"$FORMATTIMEDIFF(min, 1, 200)"}% returns 3 hours
  • Example: %CALC{"$FORMATTIMEDIFF(min, 2, 200)"}% returns 3 hours and 20 minutes
  • Example: %CALC{"$FORMATTIMEDIFF(min, 1, 1640)"}% returns 1 day
  • Example: %CALC{"$FORMATTIMEDIFF(min, 2, 1640)"}% returns 1 day and 3 hours
  • Example: %CALC{"$FORMATTIMEDIFF(min, 3, 1640)"}% returns 1 day, 3 hours and 20 minutes
>
>
  • Example: %CALC{$FORMATTIMEDIFF(min, 1, 200)}% returns 3 hours
  • Example: %CALC{$FORMATTIMEDIFF(min, 2, 200)}% returns 3 hours and 20 minutes
  • Example: %CALC{$FORMATTIMEDIFF(min, 1, 1640)}% returns 1 day
  • Example: %CALC{$FORMATTIMEDIFF(min, 2, 1640)}% returns 1 day and 3 hours
  • Example: %CALC{$FORMATTIMEDIFF(min, 3, 1640)}% returns 1 day, 3 hours and 20 minutes
 

GET( name ) -- get the value of a previously set variable

  • 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 )
Changed:
<
<
  • Example: %CALC{"$GET(my_total)"}% returns the value of the my_total variable
>
>
  • Example: %CALC{$GET(my_total)}% returns the value of the my_total variable
 

HEXDECODE( hexcode ) -- convert hexadecimal code to string

  • Decode a hexadecimal string, typically encoded with $HEXENCODE().
  • Syntax: $HEXDECODE( hexcode )
Changed:
<
<
  • Example: %CALC{"$HEXDECODE(687474703A2F2F7477696B692E6F72672F)"}% returns http://twiki.org/
>
>
  • Example: %CALC{$HEXDECODE(687474703A2F2F7477696B692E6F72672F)}% returns http://twiki.org/
 

HEXENCODE( text ) -- encode text into hexadecimal code

  • Each character of text is encoded into two hexadecimal numbers.
  • Syntax: $HEXENCODE( text )
Changed:
<
<
  • Example: %CALC{"$HEXENCODE(http://twiki.org/)"}% returns 687474703A2F2F7477696B692E6F72672F
>
>
  • Example: %CALC{$HEXENCODE(http://twiki.org/)}% returns 687474703A2F2F7477696B692E6F72672F
 

IF( condition, value if true, value if 0 ) -- return a value based on a condition

  • The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than).
  • Syntax: $IF( condition, value if true, value if 0 )
Changed:
<
<
  • 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
  • Related: $AND(), $EMPTY(), $EXACT(), $LISTIF(), $NOT(), $OR(), $WHILE()
>
>
 

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 )
Changed:
<
<
>
>
 

INT( formula ) -- evaluate formula and return integer truncated towards 0

Line: 332 to 362
 
  • Numbers may be decimal integers (1234), binary integers (0b1110011), octal integers (01234), hexadecimal integers (0x1234) or of exponential notation (12.34e-56)
  • If you expect a single decimal integer value with leading zeros, use $INT( $VALUE( number ) )
  • Syntax: $INT( formula )
Changed:
<
<
  • Example: %CALC{"$INT(10 / 4)"}% returns 2
  • Example: %CALC{"$INT($VALUE(09))"}% returns 9
>
>
  • Example: %CALC{$INT(10 / 4)}% returns 2
  • Example: %CALC{$INT($VALUE(09))}% returns 9
 
Added:
>
>

ISDIGIT( text ) -- test for digits

ISLOWER( text ) -- test for lower case text

ISUPPER( text ) -- test for upper case text

ISWIKIWORD( text ) -- test for WikiWord

 

LEFT( ) -- address range of cells to the left of the current cell

  • Syntax: $LEFT( )
Changed:
<
<
  • Example: %CALC{"$SUM($LEFT())"}% returns the sum of cells to the left of the current cell
>
>
  • Example: %CALC{$SUM($LEFT())}% returns the sum of cells to the left of the current cell
 

LEFTSTRING( text, num ) -- extract characters at the beginning of a text string

  • Retrieve the num of characters from the left end of text; the leftmost character is returned if num is missing
  • Syntax: $LEFTSTRING( text, num )
Changed:
<
<
>
>
 

LENGTH( text ) -- length of text in bytes

  • Syntax: $LENGTH( text )
Changed:
<
<
  • Example: %CALC{"$LENGTH(abcd)"}% returns 4
>
>
  • Example: %CALC{$LENGTH(abcd)}% returns 4
 

LIST( range ) -- convert content of a cell range into a list

  • 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 )
Changed:
<
<
  • Example: %CALC{"$LIST($LEFT())"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
>
>
  • Example: %CALC{$LIST($LEFT())}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
 

LISTIF( condition, list ) -- remove elements from a list that do not meet a condition

  • In addition to the condition described in $IF(), you can use $item to indicate the current element, and $index for the list index, starting at 1
  • Syntax: $LISTIF( condition, list )
Changed:
<
<
  • 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
>
>
  • 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
 

LISTITEM( index, list ) -- get one element of a list

  • Index is 1 to size of list; use a negative number to count from the end of the list
  • Syntax: $LISTITEM( index, list )
Changed:
<
<
  • Example: %CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
  • Example: %CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
>
>
  • Example: %CALC{$LISTITEM(2, Apple, Orange, Apple, Kiwi)}% returns Orange
  • Example: %CALC{$LISTITEM(-1, Apple, Orange, Apple, Kiwi)}% returns Kiwi
 

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, $sp for space, and $empty to join a list without a separator.
  • Syntax: $LISTJOIN( separator, list )
Changed:
<
<
  • Example: %CALC{"$LISTJOIN($n, Apple, Orange, Apple, Kiwi)"}% returns the four items separated by new lines
  • Example: %CALC{"$LISTJOIN($empty, Apple, Orange, Apple, Kiwi)"}% returns AppleOrangeAppleKiwi
>
>
  • Example: %CALC{$LISTJOIN($n, Apple, Orange, Apple, Kiwi)}% returns the four items separated by new lines
  • Example: %CALC{$LISTJOIN($empty, Apple, Orange, Apple, Kiwi)}% returns AppleOrangeAppleKiwi
 

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. If $item is omitted, the item is appended to the formula.
  • Syntax: $LISTMAP( formula, list )
Changed:
<
<
  • Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
>
>
  • Example: %CALC{$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)}% returns 1: 6, 2: 10, 3: 14, 4: 22
 

LISTNONEMPTY( list ) -- remove all empty elements from a list

  • Syntax: $LISTNONEMPTY( list )
Changed:
<
<
  • Example: %CALC{"$LISTNONEMPTY(, Apple, Orange, , Kiwi)"}% returns Apple, Orange, Kiwi
>
>
  • Example: %CALC{$LISTNONEMPTY(, Apple, Orange, , Kiwi)}% returns Apple, Orange, Kiwi
 

LISTRAND( list ) -- get one random element of a list

  • Syntax: $LISTRAND( list )
Changed:
<
<
  • Example: %CALC{"$LISTRAND(Apple, Orange, Apple, Kiwi)"}% returns one of the four elements
>
>
  • Example: %CALC{$LISTRAND(Apple, Orange, Apple, Kiwi)}% returns one of the four elements
 

LISTREVERSE( list ) -- opposite order of a list

  • Syntax: $LISTREVERSE( list )
Changed:
<
<
  • Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
>
>
  • Example: %CALC{$LISTREVERSE(Apple, Orange, Apple, Kiwi)}% returns Kiwi, Apple, Orange, Apple
 
Deleted:
<
<

LISTSIZE( list ) -- number of elements in a list

 

LISTSHUFFLE( list ) -- shuffle element of a list in random order

  • Syntax: $LISTSHUFFLE( list )
Changed:
<
<
  • Example: %CALC{"$LISTSHUFFLE(Apple, Orange, Apple, Kiwi)"}% returns the four elements in random order
>
>
  • Example: %CALC{$LISTSHUFFLE(Apple, Orange, Apple, Kiwi)}% returns the four elements in random order
 
Added:
>
>

LISTSIZE( list ) -- number of elements in a list

 

LISTSORT( list ) -- sort a list

  • Sorts a list in ASCII order, or numerically if all elements are numeric
  • Syntax: $LISTSORT( list )
Changed:
<
<
  • Example: %CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
>
>
  • Example: %CALC{$LISTSORT(Apple, Orange, Apple, Kiwi)}% returns Apple, Apple, Kiwi, Orange
 

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 )
Changed:
<
<
  • Example: %CALC{"$LISTTRUNCATE(2, Apple, Orange, Kiwi)"}% returns Apple, Orange
>
>
  • Example: %CALC{$LISTTRUNCATE(2, Apple, Orange, Kiwi)}% returns Apple, Orange
 

LISTUNIQUE( list ) -- remove all duplicates from a list

  • Syntax: $LISTUNIQUE( list )
Changed:
<
<
  • Example: %CALC{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"}% returns Apple, Orange, Kiwi
>
>
  • Example: %CALC{$LISTUNIQUE(Apple, Orange, Apple, Kiwi)}% returns Apple, Orange, Kiwi
 

LN( num ) -- natural logarithm of a number

  • LN is the inverse of the EXP function
  • Syntax: $LN( num )
Changed:
<
<
  • Example: %CALC{"$LN(10)"}% returns 2.30258509299405
>
>
  • Example: %CALC{$LN(10)}% returns 2.30258509299405
 

LOG( num, base ) -- logarithm of a number to a given base

  • base-10 logarithm of a number (if base is 0 or not specified), else logarithm of a number to the given base
  • Syntax: $LOG( num, base )
Changed:
<
<
  • Example: %CALC{"$LOG(1000)"}% returns 3
  • Example: %CALC{"$LOG(16, 2)"}% returns 4
>
>
  • Example: %CALC{$LOG(1000)}% returns 3
  • Example: %CALC{$LOG(16, 2)}% returns 4
 

LOWER( text ) -- lower case string of a text

  • Syntax: $LOWER(text)
Changed:
<
<
>
>
 

MAX( list ) - biggest value of a list or range of cells

  • Syntax: $MAX( list )
Changed:
<
<
  • Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX($LEFT())"}%
>
>
  • 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 )
Changed:
<
<
  • Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
>
>
  • Example: %CALC{$MEDIAN(3, 9, 4, 5)}% returns 4.5
 

MIN( list ) -- smallest value of a list or range of cells

  • Syntax: $MIN( list )
Changed:
<
<
  • Example: %CALC{"$MIN(15, 3, 28)"}% returns 3
>
>
  • Example: %CALC{$MIN(15, 3, 28)}% returns 3
 

MOD( num, divisor ) -- reminder after dividing num by divisor

  • Syntax: $MOD( num, divisor )
Changed:
<
<
  • Example: %CALC{"$MOD(7, 3)"}% returns 1
  • Related: $EVAL()
>
>
 

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 )
Changed:
<
<
  • Example: %CALC{"$SET(msg, $NOEXEC(Hi $GET(name)))"}% sets the msg variable with the formula Hi $GET(name) without executing it
>
>
  • Example: %CALC{$SET(msg, $NOEXEC(Hi $GET(name)))}% sets the msg variable with the formula Hi $GET(name) without executing it
 

Line: 506 to 570
 

NOT( num ) -- reverse logic of a number

  • Returns 0 if num is not zero, 1 if zero
  • Syntax: $NOT( num )
Changed:
<
<
  • Example: %CALC{"$NOT(0)"}% returns 1
>
>
  • Example: %CALC{$NOT(0)}% returns 1
 

ODD( num ) -- test for odd number

  • Syntax: $ODD( num )
Changed:
<
<
>
>
 

OR( list ) -- logical OR of a list

  • Syntax: $OR( list )
Changed:
<
<
  • Example: %CALC{"$OR(1, 0, 1)"}% returns 1
>
>
  • Example: %CALC{$OR(1, 0, 1)}% returns 1
 

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 )
Changed:
<
<
  • Example: %CALC{"$PERCENTILE(75, 400, 200, 500, 100, 300)"}% returns 450
>
>
  • Example: %CALC{$PERCENTILE(75, 400, 200, 500, 100, 300)}% returns 450
 

PI( ) -- mathematical constant Pi, 3.14159265358979

  • Syntax: $PI( )
Changed:
<
<
  • Example: %CALC{"$PI()"}% returns 3.14159265358979
>
>
  • Example: %CALC{$PI()}% returns 3.14159265358979
 

PRODUCT( list ) -- product of a list or range of cells

  • Syntax: $PRODUCT( list )
Changed:
<
<
  • Example: To calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
>
>
  • Example: To calculate the product of the cells to the left of the current one use %CALC{$PRODUCT($LEFT())}%
 

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 )
Changed:
<
<
>
>
 

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 )
Changed:
<
<
  • 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()
>
>
  • 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: $ISWIKIWORD(), $LOWER(), $PROPER(), $TRIM(), $UPPER()
 

RAND( max ) -- random number

Line: 563 to 627
 

REPEAT( text, num ) -- repeat text a number of times

  • Syntax: $REPEAT( text, num )
Changed:
<
<
  • Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
>
>
  • Example: %CALC{$REPEAT(/\, 5)}% returns /\/\/\/\/\
 

REPLACE( text, start, num, new ) -- replace part of a text string

  • 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 )
Changed:
<
<
>
>
 

RIGHT( ) -- address range of cells to the right of the current cell

  • Syntax: $RIGHT( )
Changed:
<
<
  • Example: %CALC{"$SUM($RIGHT())"}% returns the sum 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
 

RIGHTSTRING( text, num ) -- extract characters at the end of a text string

  • Retrieve the num of characters from the right end of text; the rightmost character is returned if num is missing
  • Syntax: $RIGHTSTRING( text, num )
Changed:
<
<
>
>
 

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
  • Syntax: $ROUND( formula, digits )
Changed:
<
<
  • Example: %CALC{"$ROUND(3.15, 1)"}% returns 3.2
  • Example: %CALC{"$ROUND(3.149, 1)"}% returns 3.1
  • Example: %CALC{"$ROUND(-2.475, 2)"}% returns -2.48
  • Example: %CALC{"$ROUND(34.9, -1)"}% returns 30
>
>
  • Example: %CALC{$ROUND(3.15, 1)}% returns 3.2
  • Example: %CALC{$ROUND(3.149, 1)}% returns 3.1
  • Example: %CALC{$ROUND(-2.475, 2)}% returns -2.48
  • Example: %CALC{$ROUND(34.9, -1)}% returns 30
 

ROW( offset ) -- current row number

  • The current table row number with an optional offset
  • Syntax: $ROW( offset )
Changed:
<
<
  • Example: To get the number of rows excluding table heading (first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
>
>
  • Example: To get the number of rows excluding table heading (first row) and summary row (last row you are in), write: %CALC{$ROW(-2)}%
 

SEARCH( string, text, start ) -- search a string within a text

  • 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 a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched
  • Syntax: $SEARCH( string, text, start )
Changed:
<
<
>
>
 

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; 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 across included topics
  • Syntax: $SET( name, value )
Changed:
<
<
  • 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
>
>
  • 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
 

SETIFEMPTY( name, value ) -- set a variable only if empty

  • Specify the variable name (alphanumeric characters and underscores) and the value.
  • Syntax: $SETIFEMPTY( name, value )
Changed:
<
<
  • Example: %CALC{"$SETIFEMPTY(result, default)"}% sets the result variable to default if the variable is empty or 0; in any case an empty string is returned
>
>
  • Example: %CALC{$SETIFEMPTY(result, default)}% sets the result variable to default if the variable is empty or 0; in any case an empty string is returned
 

SETM( name, formula ) -- update an existing variable based on a formula

  • Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables
  • Syntax: $SETM( name, formula )
Changed:
<
<
  • Example: %CALC{"$SETM(total, + $SUM($LEFT()))"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
>
>
  • Example: %CALC{$SETM(total, + $SUM($LEFT()))}% adds the sum of all table cells on the left to the total variable, and returns an empty string
 

SIGN( num ) -- sign of a number

  • Returns -1 if num is negative, 0 if zero, or 1 if positive
  • Syntax: $SIGN( num )
Changed:
<
<
>
>
 

SPLIT( separator, text ) -- split a string into a list

  • Split text into a list using separator as a delimiter. The separator may be a regular expression and may include $comma for comma, $sp for space and $empty to split at each character. Default separator is one or more spaces ($sp$sp*).
  • Syntax: $SPLIT( separator, text )
Changed:
<
<
  • Example: %CALC{"$SPLIT(, Apple Orange Kiwi)"}% returns Apple, Orange, Kiwi
  • Example: %CALC{"$SPLIT(-, Apple-Orange-Kiwi)"}% returns Apple, Orange, Kiwi
  • Example: %CALC{"$SPLIT([-:]$sp*, Apple-Orange: Kiwi)"}% returns Apple, Orange, Kiwi (the separator means: Dash or colon, followed by optional spaces
  • Example: %CALC{"$SPLIT($empty, Apple)"}% returns A, p, p, l, e
>
>
  • Example: %CALC{$SPLIT(, Apple Orange Kiwi)}% returns Apple, Orange, Kiwi
  • Example: %CALC{$SPLIT(-, Apple-Orange-Kiwi)}% returns Apple, Orange, Kiwi
  • Example: %CALC{$SPLIT([-:]$sp*, Apple-Orange: Kiwi)}% returns Apple, Orange, Kiwi (the separator means: Dash or colon, followed by optional spaces
  • Example: %CALC{$SPLIT($empty, Apple)}% returns A, p, p, l, e
 

SQRT( num ) -- square root of a number

  • Syntax: $SQRT( num )
Changed:
<
<
  • Example: %CALC{"$SQRT(16)"}% returns 4
>
>
  • Example: %CALC{$SQRT(16)}% returns 4
 

SUBSTITUTE( text, old, new, instance, option ) -- substitute text

  • Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r
  • Syntax: $SUBSTITUTE( text, old, new, instance, option )
Changed:
<
<
>
>
 

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 )
Changed:
<
<
>
>
 

SUM( list ) -- sum of a list or range of cells

  • Syntax: $SUM( list )
Changed:
<
<
  • Example: To sum up column 5 excluding the title row, write %CALC{"$SUM(R2:C5..R$ROW(-1):C5)"}% in the last row; or simply %CALC{"$SUM($ABOVE())"}%
>
>
  • Example: To sum up column 5 excluding the title row, write %CALC{$SUM(R2:C5..R$ROW(-1):C5)}% in the last row; or simply %CALC{$SUM($ABOVE())}%
 

SUMDAYS( list ) -- sum the days in a list or range of cells

  • The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours
  • Syntax: $SUMDAYS( list )
Changed:
<
<
  • Example: %CALC{"$SUMDAYS(2w, 1, 2d, 4h)"}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
>
>
  • Example: %CALC{$SUMDAYS(2w, 1, 2d, 4h)}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
 

SUMPRODUCT( list, list ) -- scalar product on ranges of cells

  • Syntax: $SUMPRODUCT( list, list, list... )
Changed:
<
<
  • 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))
>
>
  • 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))
 

T( address ) -- content of a cell

  • Syntax: $T( address )
Changed:
<
<
  • Example: %CALC{"$T(R1:C5)"}% returns the text in cell R1:C5
>
>
  • Example: %CALC{$T(R1:C5)}% returns the text in cell R1:C5
 
Deleted:
<
<

TRANSLATE( text, from, to ) -- translate text from one set of characters to another

 

TIME( text ) -- convert a date string into a serialized date number

  • Serialized date is seconds since the Epoch, e.g. midnight, 01 Jan 1970. Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 31 Dec 2003 - 23:59; 31 Dec 2003 - 23:59:59; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. DOY (Day of Year) formats: DOY2003.365, DOY2003.365.23.59, DOY2003.365.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone
  • Syntax: $TIME( text )
Changed:
<
<
  • Example: %CALC{"$TIME(2003/10/14 GMT)"}% returns 1066089600
>
>
  • Example: %CALC{$TIME(2003/10/14 GMT)}% returns 1066089600
 

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 )
Changed:
<
<
  • Example: %CALC{"$TIMEADD($TIME(), 2, week)"}% returns the serialized date two weeks from now
>
>
  • Example: %CALC{$TIMEADD($TIME(), 2, week)}% returns the serialized date two weeks from now
 

Line: 725 to 781
 
  • The unit is seconds if not specified; unit can be specified as in $TIMEADD().
  • Notes: An approximation is used for month and year calculations. Use $ROUND() to round day unit to account for daylight savings time change. Use $FORMAT(), $FORMATTIMEDIFF() or $INT() to format real numbers
  • Syntax: $TIMEDIFF( serial_1, serial_2, unit )
Changed:
<
<
  • Example: %CALC{"$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)"}% returns 1.5
  • Example: %CALC{"$ROUND($TIMEDIFF($TIME(2009/03/06),$TIME(2009/03/13), day))"}% returns 7 (or 6.95833333333333 without the $ROUND())
>
>
  • Example: %CALC{$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)}% returns 1.5
  • Example: %CALC{$ROUND($TIMEDIFF($TIME(2009/03/06),$TIME(2009/03/13), day))}% returns 7 (or 6.95833333333333 without the $ROUND())
 

TODAY( ) -- serialized date of today at midnight GMT

  • In contrast, the related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT
  • Syntax: $TODAY( )
Changed:
<
<
  • Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
>
>
  • Example: %CALC{$TODAY()}% returns the number of seconds since Epoch
 
Added:
>
>

TRANSLATE( text, from, to ) -- translate text from one set of characters to another

 

TRIM( text ) -- trim spaces from text

  • Removes all spaces from text except for single spaces between words
  • Syntax: $TRIM( text )
Changed:
<
<
>
>
 

UPPER( text ) -- upper case string of a text

  • Syntax: $UPPER( text )
Changed:
<
<
>
>
 

VALUE( text ) -- convert text to number

  • Extracts a number from text. Returns 0 if not found
  • Syntax: $VALUE( text )
Changed:
<
<
  • Example: %CALC{"$VALUE(US$1,200)"}% returns 1200
  • Example: %CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
  • Example: %CALC{"$VALUE(Total: -12.5)"}% returns -12.5
  • Related: $CEILING(), $EVAL(), $FLOOR(), $INT(), $ROUND()
>
>
 

WHILE( condition, do ) -- do something while a condition is true

  • The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than).
  • The condition and do are evaluated in each cycle; a $counter starting at 1 can be used in condition and do.
  • Syntax: $WHILE( condition, do something )
Changed:
<
<
  • Example: %CALC{"$WHILE($counter<=10, $counter )"}% returns 1 2 3 4 5 6 7 8 9 10
  • Example: %CALC{"$SET(i, 0) $WHILE($GET(i)<10, $SETM(i, +1) $EVAL($GET(i) * $GET(i)), )"}% returns 1, 4, 9, 16, 25, 36, 49, 64, 81, 100,
>
>
  • Example: %CALC{$WHILE($counter<=10, $counter )}% returns 1 2 3 4 5 6 7 8 9 10
  • Example: %CALC{$SET(i, 0) $WHILE($GET(i)<10, $SETM(i, +1) $EVAL($GET(i) * $GET(i)), )}% returns 1, 4, 9, 16, 25, 36, 49, 64, 81, 100,
 

WORKINGDAYS( serial_1, serial_2 ) -- working days between two serialized dates

  • Working days are Monday through Friday (sorry, Israel!)
  • Syntax: $WORKINGDAYS( serial_1, serial_2 )
Changed:
<
<
  • Example: %CALC{"$WORKINGDAYS($TIME(2004/07/15), $TIME(2004/08/03))"}% returns 13
>
>
  • Example: %CALC{$WORKINGDAYS($TIME(2004/07/15), $TIME(2004/08/03))}% returns 13
 

XOR( list ) -- logical XOR of a list

  • Syntax: $XOR( list )
Changed:
<
<
  • Example: %CALC{"$XOR(0, 0)"}% returns 0
  • Example: %CALC{"$XOR(0, 1)"}% returns 1
  • Example: %CALC{"$XOR(1, 0)"}% returns 1
  • Example: %CALC{"$XOR(1, 1)"}% returns 0
  • Example: %CALC{"$XOR(1, 0, 1)"}% returns 0
>
>
  • Example: %CALC{$XOR(0, 0)}% returns 0
  • Example: %CALC{$XOR(0, 1)}% returns 1
  • Example: %CALC{$XOR(1, 0)}% returns 1
  • Example: %CALC{$XOR(1, 1)}% returns 0
  • Example: %CALC{$XOR(1, 0, 1)}% returns 0
 

FAQ

Line: 791 to 855
  Specifically, how can I output some conditional text in a FormattedSearch?
Changed:
<
<
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%/%SYSTEMWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-no.gif) in the format="" parameter, write this:
>
>
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), %ICONURL{choice-yes}%, %ICONURL{choice-no}%) in the format="" parameter, write this:
 
Changed:
<
<
%SEARCH{ .... format="| $topic | $percntCALC{$IF($EXACT($formfield(Tested), Yes), %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-no.gif)}$percnt |" }%
>
>
%SEARCH{ .... format="| $topic | $percntCALC{$IF($EXACT($formfield(Tested), Yes), %ICONURL{choice-yes}%, %ICONURL{choice-no}%)}$percnt |" }%
 

How can I easily repeat a formula in a table?

Line: 817 to 881
 
  • Set SPREADSHEETPLUGIN_SKIPINCLUDE = 0
Changed:
<
<
This setting tells the SpreadSheetPlugin to process the CALCs in the included page, e.g. it will not delay the evaluation of the formulae.
>
>
This setting tells the SpreadSheetPlugin to process the CALCs in the included page, e.g. it will not delay the evaluation of the functions.
 

Bug Tracking Example

Line: 826 to 890
 
Bug:1232 High Memory Window ... Fixed 2
Bug:1233 Medium Usability issue ... Assigned 5
Bug:1234 High No arrange ... Fixed 1
Changed:
<
<
Total: -1 %CALC{"$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}%: 1 . %CALC{"$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}%: 1 Total: 0
>
>
Total: -1 %CALC{$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )}%: 1 . %CALC{$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )}%: 1 Total: 0
  The last row is defined as:
Changed:
<
<
| Total: -2 \ | R2:C0..R-1:C0: 1 | . \ | R2:C0..R-1:C0: 1 \
Total: 0
>
>
| Total: -2 \ | R2:C0..R-1:C0: 1 | . \ | R2:C0..R-1:C0: 1 \
Total: 0
 
Changed:
<
<
Above table is created manually. The table can be build dynamically with a formatted search, or by a plugin that pulls data from an external source, such as a bug tracking system.
>
>
Above table is created manually. The table can be build dynamically with a formatted search, or by a plugin that pulls data from an external source, such as a bug tracking system.
 

Plugin Settings

Line: 863 to 927
 

Plugin Installation Instructions

Changed:
<
<
Note: You do not need to install anything on the browser to use this plugin. Below installation instructions are for the administrator who needs to install this plugin on the TWiki server.
>
>
Note: This plugin is pre-installed. TWiki administrators can upgrade it as needed on the TWiki server.

  • For an automated installation, run the configure script and follow "Find More Extensions" in the in the Extensions section.
 
Changed:
<
<
  • Download the ZIP file from the SpreadSheetPlugin home
>
>
  • Or, follow these manual installation steps:
    • Download the ZIP file from the Plugins home (see below).
 
  • Unzip SpreadSheetPlugin.zip in your twiki installation directory. Content:
    File: Description:
    data/TWiki/SpreadSheetPlugin.txt Plugin topic
Changed:
<
<
data/TWiki/SpreadSheetPlugin.txt,v Plugin topic repository
>
>
data/TWiki/VarCALC.txt Documentation of the CALC variable
data/TWiki/VarCALCULATE.txt Documentation of the CALCULATE variable
 
lib/TWiki/Plugins/SpreadSheetPlugin.pm Plugin Perl module
Changed:
<
<
  • 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.
>
>
lib/TWiki/Plugins/SpreadSheetPlugin/Calc.pm Plugin core module
    • Set the ownership of the extracted directories and files to the webserver user.

  • Plugin configuration and testing:
    • Run the configure script and enable the plugin in the Plugins section.
    • Test if the installation was successful: See example above.
 

Plugin Info

Plugin Author: TWiki:Main.PeterThoeny
Changed:
<
<
Copyright: © 2001-2012 Peter Thoeny, Twiki, Inc.
© 2008-2012 TWiki:TWiki.TWikiContributor
>
>
Copyright: © 2001-2012 Peter Thoeny, TWiki.org
© 2008-2012 TWiki:TWiki.TWikiContributor
 
License: GPL (GNU General Public License)
Changed:
<
<
Plugin Version: 2012-01-13
>
>
Plugin Version: 2012-10-06
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
2012-10-06: TWikibug:Item6960: Fixed form action of interactive formula evaluation feature -- TWiki:Main.HideyoImazu
2012-06-30: TWikibug:Item6898: Added $FILTER()
2012-06-29: TWikibug:Item6897: Added $ISDIGIT(), $ISLOWER(), $ISUPPER(), $ISWIKIWORD()
2012-04-04: TWikibug:Item6866: Added CALCULATE variable using register tag handler to support proper inside-out, left-to-right eval order like ordinary TWiki variables
 
2012-01-13: TWikibug:Item6804: Added $FLOOR() and $CEILING()
2011-09-07: TWikibug:Item6803: Fix for EVAL function bug with zeroes after decimal point
2011-07-09: TWikibug:Item6725: Change global package variables from "use vars" to "our"
Line: 952 to 1028
 
Feedback: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginAppraisal
Changed:
<
<
Related Topics: TWikiPreferences, TWikiPlugins, VarCALC, VarIF
>
>
Related Topics: TWikiPreferences, TWikiPlugins, VarCALC, VarCALCULATE, VarIF

Revision 242012-01-14 - TWikiContributor

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Revision 232011-07-10 - TWikiContributor

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Revision 222011-04-09 - TWikiContributor

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Revision 212010-08-27 - TWikiContributor

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Revision 202010-05-23 - TWikiContributor

Line: 1 to 1
Added:
>
>

TWiki Spreadsheet Plugin

 
Deleted:
<
<

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.
Line: 25 to 25
 
Changed:
<
<
Formula: %CALC{"TWikiGuest)" />"}%  
>
>
Formula: %CALC{"TWikiGuest)" class="twikiInputField" />"}%
 Result:     TWiki Guest
Deleted:
<
<
 
Line: 41 to 42
 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)
Changed:
<
<
  • Functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
>
>
  • Functions may be nested, such as %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
 
  • Functions are evaluated from left to right, and from inside to outside if nested
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
Changed:
<
<
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. %CALC{"$SUM( 3, 5, 7 )"}%
>
>
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, such as %CALC{"$SUM( 3, 5, 7 )"}%
 
  • A table cell can be addressed as R1:C1. Table address matrix:
    R1:C1 R1:C2 R1:C3 R1:C4
    R2:C1 R2:C2 R2:C3 R2:C4
  • A table cell range is defined by two cell addresses separated by "..", e.g. "row 1 through 20, column 3" is: R1:C3..R20:C3
Changed:
<
<
  • Lists can refer to values and/or table cell ranges, e.g. %CALC{"$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )"}%
>
>
  • Lists can refer to values and/or table cell ranges, such as %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
  • Formulae can be placed in a FormattedSearch, but the CALC needs to be escaped. Learn how to use a CALC in a formatted search
Changed:
<
<
>
>
  • Plain text can be added, such as %CALC{"Total: $SUM($ABOVE()) kg"}%
 

Built-in Functions

Line: 429 to 430
 

NOP( text ) -- no-operation

Changed:
<
<
  • 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 preprocessing to be done before %SEARCH{}% is evaluated. The percent character '%' can be escaped with $percnt. The quote character '"' can be escaped with $quot.
 
  • Syntax: $NOP( text )

Line: 627 to 628
 

TIME( text ) -- convert a date string into a serialized date number

Changed:
<
<
  • Serialized date is seconds since the Epoch, e.g. midnight, 01 Jan 1970. Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone
>
>
  • Serialized date is seconds since the Epoch, e.g. midnight, 01 Jan 1970. Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 31 Dec 2003 - 23:59; 31 Dec 2003 - 23:59:59; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. DOY (Day of Year) formats: DOY2003.365, DOY2003.365.23.59, DOY2003.365.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone
 
Line: 697 to 698
 

How can I easily repeat a formula in a table?

Changed:
<
<
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:
>
>
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 defined at the site level, web level or topic level, and may be hidden in HTML comments. Example:
 
<!--
Line: 729 to 730
 
Total: 0
Changed:
<
<
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. The table can be build dynamically with a formatted search, or by a plugin that pulls data from an external source, such as a bug tracking system.
 

Plugin Settings

Line: 737 to 738
 a plugin setting write %<plugin>_<setting>%, i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%

Changed:
<
<
    • Set SHORTDESCRIPTION = Add spreadsheet calculation like "$SUM( $ABOVE() )" to TWiki tables and other topic text
>
>
    • Set SHORTDESCRIPTION = Add spreadsheet calculation like "$SUM( $ABOVE() )" to TWiki tables or anywhere in topic text
 
  • Debug plugin: (See output in data/debug.txt)
    • Set DEBUG = 0
Line: 767 to 768
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Copyright: © 2001-2009, Peter Thoeny, TWIKI.NET
>
>
Copyright: © 2001-2010, Peter Thoeny, Twiki, Inc.
 
License: GPL (GNU General Public License)
Changed:
<
<
Plugin Version: 09 May 2009 (18078)
>
>
Plugin Version: 18825 (2010-05-29) (2010-05-15)
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
2010-05-22: TWikibug:Item6472 - adding support for DOY in $TIME(), contributed by TWiki:Main/EmanueleCupido
2010-05-15: TWikibug:Item6433 - doc improvements; replacing TWIKIWEB with SYSTEMWEB
2010-02-27: Doc improvements
2009-11-22: Enhanced $NOP(): Added $quot replacement for quote character, changed $per replacement with $percnt, contributed by TWiki:Main/HorstEsser
 
09 May 2009: Fixed bug in $WORKINGDAYS(): Incorrect number of days if daylight savings time change happens between start date and end date
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()
Changed:
<
<
02 Jun 2007: Added VarCALC to have %CALC{}% listed in TWikiVariables
>
>
02 Jun 2007: Added VarCALC to have %CALC{}% listed in TWikiVariables
 
14 Apr 2007: Fixing bug in $EXISTS() that required full web.topic instead of just topic
11 Mar 2007: Fixing bug in $VALUE() and $INT(), introduced by version 09 Mar 2007
09 Mar 2007: Added $EXP(), $LN(), $LOG(), $PI(), $SQRT(); fixed $ROUND() bug, contributed by TWiki:Main/SergejZnamenskij
Line: 823 to 828
 
Feedback: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginAppraisal
Changed:
<
<
Related Topics: TWikiPreferences, TWikiPlugins, VarCALC

-- TWiki:Main/PeterThoeny - 26 Mar 2009

>
>
Related Topics: TWikiPreferences, TWikiPlugins, VarCALC, VarIF

Revision 192009-05-10 - TWikiContributor

Line: 1 to 1
 

Revision 182009-03-27 - TWikiContributor

Line: 1 to 1
Added:
>
>
<--
   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

Changed:
<
<
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.
>
>
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.
 
Example:
Line: 25 to 31
 
Changed:
<
<
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.)
 

On this page:

Syntax Rules

Changed:
<
<
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) )"}%
Line: 46 to 52
 
  • 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
Added:
>
>
 

Built-in Functions

Line: 118 to 126
 
Added:
>
>

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
Line: 138 to 155
 
  • Syntax: $EXACT( text1, text2 )
  • Example: %CALC{"$EXACT(foo, Foo)"}% returns 0
  • Example: %CALC{"$EXACT(foo, $LOWER(Foo))"}% returns 1
Changed:
<
<
>
>
 

EXEC( formula ) -- execute a spreadsheet formula

Line: 155 to 172
 
  • Syntax: $EXISTS( topic )
  • Example: %CALC{"$EXISTS(WebHome)"}% returns 1
  • Example: %CALC{"$EXISTS(ThisDoesNotExist)"}% returns 0
Added:
>
>
 

EXP( num ) -- exponent (e) raised to the power of a number

Line: 170 to 188
 
  • Example: %CALC{"$FIND(f, fluffy)"}% returns 1
  • Example: %CALC{"$FIND(f, fluffy, 2)"}% returns 4
  • Example: %CALC{"$FIND(@, fluffy, 1)"}% returns 0
Changed:
<
<
>
>
 

FORMAT( type, precision, number ) -- format a number to a certain type and precision

Line: 235 to 253
 
  • 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
Changed:
<
<
>
>

INSERTSTRING( text, start, new ) -- insert a string into a text string

 

INT( formula ) -- evaluate formula and round down to nearest integer

Line: 253 to 279
 
  • Example: %CALC{"$SUM($LEFT())"}% returns the sum of cells to the left of the current cell
  • Related: $ABOVE(), $RIGHT()
Added:
>
>

LEFTSTRING( text, num ) -- extract characters at the beginning of a text string

 

LENGTH( text ) -- length of text in bytes

  • Syntax: $LENGTH( text )
Line: 273 to 307
 
  • 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
Changed:
<
<
>
>
 

LISTITEM( index, list ) -- get one element of a list

Line: 395 to 429
 

NOP( text ) -- no-operation

Changed:
<
<
  • 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
 
  • Syntax: $NOP( text )

Line: 403 to 437
 
  • Returns 0 if num is not zero, 1 if zero
  • Syntax: $NOT( num )
  • Example: %CALC{"$NOT(0)"}% returns 1
Changed:
<
<
>
>
 

ODD( num ) -- test for odd number

Line: 445 to 479
 

PROPERSPACE( text ) -- properly space out WikiWords

Changed:
<
<
  • 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()
Line: 466 to 500
 
  • 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
Changed:
<
<
>
>
 

RIGHT( ) -- address range of cells to the right of the current cell

Line: 474 to 508
 
  • Example: %CALC{"$SUM($RIGHT())"}% returns the sum of cells to the right of the current cell
  • Related: $ABOVE(), $LEFT()
Added:
>
>

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
Line: 498 to 540
 
  • Example: %CALC{"$SEARCH([uy], fluffy)"}% returns 3
  • Example: %CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
  • Example: %CALC{"$SEARCH([abc], fluffy,)"}% returns 0
Changed:
<
<
>
>
 

SET( name, value ) -- set a variable for later use

Line: 541 to 583
 
  • 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
Changed:
<
<
>
>

SUBSTRING( text, start, num ) -- extract a substring out of a text string

 

SUM( list ) -- sum of a list or range of cells

Line: 574 to 623
 
  • Syntax: $TRANSLATE( text, from, to )
  • Example: %CALC{"$TRANSLATE(boom,bm,cl)"}% returns cool
  • Example: %CALC{"$TRANSLATE(one, two,$comma,;)"}% returns one; two
Changed:
<
<
>
>
 

TIME( text ) -- convert a date string into a serialized date number

Line: 609 to 658
 
  • Removes all spaces from text except for single spaces between words
  • Syntax: $TRIM( text )
  • Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces
Changed:
<
<
>
>
 

UPPER( text ) -- upper case string of a text

Line: 635 to 684
 

FAQ

Added:
>
>
 

Can I use CALC in a formatted search?

Specifically, how can I output some conditional text in a FormattedSearch?

Line: 677 to 727
 
Total: 0
Changed:
<
<
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

Line: 709 to 759
 
data/TWiki/SpreadSheetPlugin.txt Plugin topic
data/TWiki/SpreadSheetPlugin.txt,v Plugin topic repository
lib/TWiki/Plugins/SpreadSheetPlugin.pm Plugin Perl module
Changed:
<
<
  • 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

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Copyright: © 2001-2007, Peter Thoeny, TWIKI.NET
>
>
Copyright: © 2001-2009, Peter Thoeny, TWIKI.NET
 
License: GPL (GNU General Public License)
Changed:
<
<
Plugin Version: 13 Oct 2007 (15270)
>
>
Plugin Version: 26 Mar 2009 (17910)
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
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
Line: 769 to 822
  Related Topics: TWikiPreferences, TWikiPlugins, VarCALC
Changed:
<
<
-- TWiki:Main/PeterThoeny - 13 Oct 2007
>
>
-- TWiki:Main/PeterThoeny - 26 Mar 2009

Revision 172007-10-13 - TWikiContributor

Line: 1 to 1
 

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.

Revision 162007-10-13 - PeterThoeny

Line: 1 to 1
 

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.

Line: 121 to 121
 

EVAL( formula ) -- evaluate a simple mathematical formula

  • Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
Added:
>
>
  • Numbers may be decimal integers (1234), binary integers (0b1110011), octal integers (01234), hexadecimal integers (0x1234) or of exponential notation (12.34e-56)
 
Line: 150 to 151
 

EXISTS( topic ) -- check if topic exists

Changed:
<
<
  • Topic can be TopicName or a Web.TopicName
>
>
  • Topic can be TopicName or a Web.TopicName. Current web is used if web is not specified.
 
  • Syntax: $EXISTS( topic )
  • Example: %CALC{"$EXISTS(WebHome)"}% returns 1
  • Example: %CALC{"$EXISTS(ThisDoesNotExist)"}% returns 0
Added:
>
>

EXP( num ) -- exponent (e) raised to the power of a number

  • EXP is the inverse of the LN function
  • Syntax: $EXP( num )
  • Example: %CALC{"$EXP(1)"}% returns 2.71828182845905
  • Related: $LN(), $LOG()
 

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.
Line: 165 to 173
 

Changed:
<
<

FORMAT( type, prec, number ) -- format a number to a certain type and precision

  • 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
>
>

FORMAT( type, precision, number ) -- format a number to a certain type and precision

  • Supported type:
    • COMMA for comma format, such as 12,345.68
    • DOLLAR for Dollar format, such as $12,345.68
    • KB for Kilo Byte format, such as 1205.63 KB
    • MB for Mega Byte format, such as 1.18 MB
    • KBMB for Kilo/Mega/Giga/Tera Byte auto-adjust format
    • NUMBER for number, such as 12345.7
    • PERCENT for percent format, such as 12.3%
  • The precision indicates the the number of digits after the dot
 
  • 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
Line: 176 to 192
 
  • 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%
Changed:
<
<
>
>

FORMATGMTIME( serial, text ) -- convert a serialized date into a GMT date string

 

FORMATTIME( serial, text ) -- convert a serialized date into a date string

  • The following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone.
  • Syntax: $FORMATTIME( serial, text )
  • Example: %CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
Changed:
<
<
>
>
 
Changed:
<
<

FORMATGMTIME( serial, text ) -- convert a serialized date into a GMT date string

  • The date string represents the time in Greenwich time zone. Same variable expansion as in $FORMATTIME().
  • Syntax: $FORMATGMTIME( serial, text )
  • Example: %CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
  • Related: $FORMATTIME(), $TIME(), $TIMEADD(), $TIMEDIFF(), $TODAY()
>
>

FORMATTIMEDIFF( unit, precision, time ) -- convert elapsed time to a string

  • Convert elapsed time to a human readable format, such as: 12 hours and 3 minutes
  • The input unit can be second, minute, hour, day, month, year. Note: An approximation is used for month and year calculations.
  • The precision indicates the number of output units to use
  • Syntax: $FORMATTIMEDIFF( unit, precision, time )
  • Example: %CALC{"$FORMATTIMEDIFF(min, 1, 200)"}% returns 3 hours
  • Example: %CALC{"$FORMATTIMEDIFF(min, 2, 200)"}% returns 3 hours and 20 minutes
  • Example: %CALC{"$FORMATTIMEDIFF(min, 1, 1640)"}% returns 1 day
  • Example: %CALC{"$FORMATTIMEDIFF(min, 2, 1640)"}% returns 1 day and 3 hours
  • Example: %CALC{"$FORMATTIMEDIFF(min, 3, 1640)"}% returns 1 day, 3 hours and 20 minutes
  • Related: $FORMATTIME(), $TIME(), $TIMEADD(), $TIMEDIFF()
 

GET( name ) -- get the value of a previously set variable

Line: 211 to 240
 

INT( formula ) -- evaluate formula and round down to nearest integer

  • Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
Added:
>
>
  • Numbers may be decimal integers (1234), binary integers (0b1110011), octal integers (01234), hexadecimal integers (0x1234) or of exponential notation (12.34e-56)
  • If you expect a single decimal integer value with leading zeros, use $INT( $VALUE( number ) )
 
  • Syntax: $INT( formula )
  • Example: %CALC{"$INT(10 / 4)"}% returns 2
Added:
>
>
  • Example: %CALC{"$INT($VALUE(09))"}% returns 9
 

Line: 309 to 341
 
Added:
>
>

LN( num ) -- natural logarithm of a number

  • LN is the inverse of the EXP function
  • Syntax: $LN( num )
  • Example: %CALC{"$LN(10)"}% returns 2.30258509299405
  • Related: $EXP(), $LOG()

LOG( num, base ) -- logarithm of a number to a given base

  • base-10 logarithm of a number (if base is 0 or not specified), else logarithm of a number to the given base
  • Syntax: $LOG( num, base )
  • Example: %CALC{"$LOG(1000)"}% returns 3
  • Example: %CALC{"$LOG(16, 2)"}% returns 4
  • Related: $EXP(), $LN()
 

LOWER( text ) -- lower case string of a text

  • Syntax: $LOWER(text)
Line: 377 to 424
 
Added:
>
>

PI( ) -- mathematical constant Pi, 3.14159265358979

  • Syntax: $PI( )
  • Example: %CALC{"$PI()"}% returns 3.14159265358979
 

PRODUCT( list ) -- product of a list or range of cells

  • Syntax: $PRODUCT( list )
Line: 387 to 439
 

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 )
Changed:
<
<
  • Example: %CALC{"PROPER(a small STEP)"}% returns A Small Step
  • Example: %CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula-1)
>
>
  • Example: %CALC{"$PROPER(a small STEP)"}% returns A Small Step
  • Example: %CALC{"$PROPER(f1 (formula-1))"}% returns F1 (Formula-1)
 

PROPERSPACE( text ) -- properly space out WikiWords

Changed:
<
<
  • 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()
Line: 441 to 493
 

SEARCH( string, text, start ) -- search a string within a text

Changed:
<
<
  • 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 a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched
>
>
  • 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 a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched
 
  • Syntax: $SEARCH( string, text, start )
  • Example: %CALC{"$SEARCH([uy], fluffy)"}% returns 3
  • Example: %CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
Line: 476 to 528
 
Added:
>
>

SQRT( num ) -- square root of a number

  • Syntax: $SQRT( num )
  • Example: %CALC{"$SQRT(16)"}% returns 4
 

SUBSTITUTE( text, old, new, instance, option ) -- substitute text

Changed:
<
<
  • Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r
>
>
  • Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r
 
  • Syntax: $SUBSTITUTE( text, old, new, instance, option )
  • Example: %CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
  • Example: %CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
Line: 524 to 581
 
  • Serialized date is seconds since the Epoch, e.g. midnight, 01 Jan 1970. Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone
  • Syntax: $TIME( text )
  • Example: %CALC{"$TIME(2003/10/14 GMT)"}% returns 1066089600
Changed:
<
<
>
>
 

TIMEADD( serial, value, unit ) -- add a value to a serialized date

Changed:
<
<
  • 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
>
>
  • 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
 

TIMEDIFF( serial_1, serial_2, unit ) -- time difference between two serialized dates

Changed:
<
<
  • The unit is seconds if not specified; unit can be specified as in $TIMEADD(). Note: An approximation is used for month and year calculations. Use $FORMAT() or $INT() to format real numbers
>
>
  • The unit is seconds if not specified; unit can be specified as in $TIMEADD(). Note: An approximation is used for month and year calculations. Use $FORMAT(), $FORMATTIMEDIFF() or $INT() to format real numbers
 
  • Syntax: $TIMEDIFF( serial_1, serial_2, unit )
  • Example: %CALC{"$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)"}% returns 1.5
Changed:
<
<
>
>
 

TODAY( ) -- serialized date of today at midnight GMT

Line: 580 to 637
 

Can I use CALC in a formatted search?

Changed:
<
<
Specifically, how can I output some conditional text in a FormattedSearch?
>
>
Specifically, how can I output some conditional text in a FormattedSearch?
 
Changed:
<
<
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:
>
>
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%/%SYSTEMWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-no.gif) in the format="" parameter, write this:
 
Changed:
<
<
%SEARCH{ .... format="| $topic | $percntCALC{$IF($EXACT($formfield(Tested), Yes), %PUBURL%/%TWIKIWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%TWIKIWEB%/TWikiDocGraphics/choice-no.gif)}$percnt |" }%
>
>
%SEARCH{ .... format="| $topic | $percntCALC{$IF($EXACT($formfield(Tested), Yes), %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-no.gif)}$percnt |" }%
 

How can I easily repeat a formula in a table?

Line: 627 to 684
 Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
Changed:
<
<
>
>
 
    • Set SHORTDESCRIPTION = Add spreadsheet calculation like "$SUM( $ABOVE() )" to TWiki tables and other topic text

  • Debug plugin: (See output in data/debug.txt)
Line: 637 to 694
 
    • Set SKIPINCLUDE = 1

Changed:
<
<
  • WikiWords to exclude from being spaced out by the $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
>
>
  • WikiWords to exclude from being spaced out by the $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
 
Line: 658 to 715
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Copyright: © 2001-2007, Peter@Thoeny.org, StructuredWikis LLC
>
>
Copyright: © 2001-2007, Peter Thoeny, TWIKI.NET
 
License: GPL (GNU General Public License)
Changed:
<
<
Plugin Version: 23 Jan 2007 (r12607)
>
>
Plugin Version: 13 Oct 2007 (15270)
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
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
14 Apr 2007: Fixing bug in $EXISTS() that required full web.topic instead of just topic
11 Mar 2007: Fixing bug in $VALUE() and $INT(), introduced by version 09 Mar 2007
09 Mar 2007: Added $EXP(), $LN(), $LOG(), $PI(), $SQRT(); fixed $ROUND() bug, contributed by TWiki:Main/SergejZnamenskij
 
23 Jan 2007: Enhanced documentation
18 Dec 2006: Added $LISTRAND(), $LISTSHUFFLE(), $LISTTRUNCATE(); fixed spurious newline at end of topic, contributed by TWiki:Main/MichaelDaum
10 Oct 2006: Enhanced documentation
Line: 697 to 760
 
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()
CPAN Dependencies: none
Changed:
<
<
TWiki:Plugins/Benchmark: GoodStyle 99%, FormattedSearch 99%, SpreadSheetPlugin 95%
>
>
TWiki:Plugins/Benchmark: GoodStyle 99%, FormattedSearch 99%, SpreadSheetPlugin 95%
 
Other Dependencies: none
Perl Version: 5.000 and up
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginAppraisal
Changed:
<
<
Related Topics: TWikiPreferences, TWikiPlugins
>
>
Related Topics: TWikiPreferences, TWikiPlugins, VarCALC
 
Changed:
<
<
-- TWiki:Main/PeterThoeny - 23 Jan 2007
>
>
-- TWiki:Main/PeterThoeny - 13 Oct 2007
 

Revision 152007-01-24 - PeterThoeny

Line: 1 to 1
 

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.

Line: 260 to 260
 

LISTMAP( formula, list ) -- evaluate and update each element of a list

Changed:
<
<
  • In the formula you can use $item to indicate the element; $index to show the index of the list, starting at 1
>
>
  • In the formula you can use $item to indicate the element; $index to show the index of the list, starting at 1. If $item is omitted, the item is appended to the formula.
 
Line: 268 to 268
 

LISTRAND( list ) -- get one random element of a list

  • Syntax: $LISTRAND( list )
Changed:
<
<
  • Example: %CALC{"$LISTRRAND(Apple, Orange, Apple, Kiwi)"}% returns one of the four elements
>
>
  • Example: %CALC{"$LISTRAND(Apple, Orange, Apple, Kiwi)"}% returns one of the four elements
 

Line: 658 to 658
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Copyright: © 2001-2006, Peter@Thoeny.org, StructuredWikis LLC
>
>
Copyright: © 2001-2007, Peter@Thoeny.org, StructuredWikis LLC
 
License: GPL (GNU General Public License)
Changed:
<
<
Plugin Version: 18 Dec 2006 (r12315)
>
>
Plugin Version: 23 Jan 2007 (r12607)
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
23 Jan 2007: Enhanced documentation
 
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
Line: 705 to 706
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 18 Dec 2006
>
>
-- TWiki:Main/PeterThoeny - 23 Jan 2007
 

Revision 142006-12-19 - PeterThoeny

Line: 1 to 1
 

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.

Line: 232 to 232
 
  • 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 |
Changed:
<
<
>
>
 

LISTIF( condition, list ) -- remove elements from a list that do not meet a condition

Line: 249 to 249
 
  • Syntax: $LISTITEM( index, list )
  • Example: %CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
  • Example: %CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
Changed:
<
<
>
>
 

LISTJOIN( separator, list ) -- convert a list into a string

Line: 265 to 265
 
Added:
>
>

LISTRAND( list ) -- get one random element of a list

 

LISTREVERSE( list ) -- opposite order of a list

  • Syntax: $LISTREVERSE( list )
Line: 275 to 281
 

LISTSIZE( list ) -- number of elements in a list

  • Syntax: $LISTSIZE( list )
  • Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
Changed:
<
<
>
>

LISTSHUFFLE( list ) -- shuffle element of a list in random order

 

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
Changed:
<
<
>
>

LISTTRUNCATE( size, list ) -- truncate list to size

 

LISTUNIQUE( list ) -- remove all duplicates from a list

Line: 383 to 402
 

RAND( max ) -- random number

  • Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified
  • Syntax: $RAND( max )
Changed:
<
<
>
>
 
Changed:
<
<

REPEAT(text) -- repeat text a number of times

  • Syntax: $REPEAT( text )
>
>

REPEAT( text, num ) -- repeat text a number of times

  • Syntax: $REPEAT( text, num )
 
  • Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\

Line: 557 to 576
 
Added:
>
>

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

Bug#: Priority: Subject: Status: Days to fix
Line: 586 to 628
 a plugin setting write %<plugin>_<setting>%, i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%

Changed:
<
<
    • 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)
    • Set DEBUG = 0
Line: 618 to 660
 
Plugin Author: TWiki:Main/PeterThoeny
Copyright: © 2001-2006, Peter@Thoeny.org, StructuredWikis LLC
License: GPL (GNU General Public License)
Changed:
<
<
Plugin Version: 13 May 2006 (10197)
>
>
Plugin Version: 18 Dec 2006 (r12315)
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
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
Line: 661 to 705
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 13 May 2006
>
>
-- TWiki:Main/PeterThoeny - 18 Dec 2006
 

Revision 132006-05-13 - PeterThoeny

Line: 1 to 1
 

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.

Line: 66 to 66
 

Changed:
<
<

AND( list ) -- logcial AND of a list

>
>

AND( list ) -- logical AND of a list

 
  • Syntax: $AND( list )
  • Example: %CALC{"$AND(1, 0, 1)"}% returns 0
  • Related: $NOT(), $IF(), $OR()
Line: 197 to 197
 
  • 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
Changed:
<
<
>
>
 

IF( condition, value if true, value if 0 ) -- return a value based on a condition

Line: 346 to 346
 

Changed:
<
<

OR( list ) -- logcial OR of a list

>
>

OR( list ) -- logical OR of a list

 
  • Syntax: $OR( list )
  • Example: %CALC{"$OR(1, 0, 1)"}% returns 1
  • Related: $AND(), $IF(), $NOT()
Line: 376 to 376
 

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 )
Changed:
<
<
  • 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
 

Line: 431 to 431
 

SET( name, value ) -- set a variable for later use

Changed:
<
<
  • 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
>
>
  • 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 across 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
Changed:
<
<
>
>

SETIFEMPTY( name, value ) -- set a variable only if empty

  • Specify the variable name (alphanumeric characters and underscores) and the value.
  • Syntax: $SETIFEMPTY( name, value )
  • Example: %CALC{"$SETIFEMPTY(result, default)"}% sets the result variable to default if the variable is empty or 0; in any case an empty string is returned
  • Related: $GET(), $SET()
 

SETM( name, formula ) -- update an existing variable based on a formula

  • Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables
  • Syntax: $SETM( name, formula )
  • Example: %CALC{"$SETM(total, + $SUM($LEFT()))"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
Changed:
<
<
>
>
 

SIGN( num ) -- sign of a number

Line: 603 to 610
 
data/TWiki/SpreadSheetPlugin.txt Plugin topic
data/TWiki/SpreadSheetPlugin.txt,v Plugin topic repository
lib/TWiki/Plugins/SpreadSheetPlugin.pm Plugin Perl module
Changed:
<
<
  • (Dakar) 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

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 17 Jun 2005 (1.018)
>
>
Copyright: © 2001-2006, Peter@Thoeny.org, StructuredWikis LLC
License: GPL (GNU General Public License)
Plugin Version: 13 May 2006 (10197)
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
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
24 Oct 2004: Added $EXISTS(), contributed by TWiki:Main/RodrigoChandia; added $PERCENTILE()
Line: 647 to 657
 
Perl Version: 5.000 and up
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev
Added:
>
>
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginAppraisal
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 17 Jun 2005
>
>
-- TWiki:Main/PeterThoeny - 13 May 2006
 

Revision 122005-06-27 - TWikiContributor

Line: 1 to 1
 

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.

Revision 112005-06-27 - PeterThoeny

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Changed:
<
<
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.
 
Example:
Line: 63 to 63
 

ABS( num ) -- absolute value of a number

  • Syntax: $ABS( num )
  • Example: %CALC{"$ABS(-12.5)"}% returns 12.5
Changed:
<
<
>
>
 

AND( list ) -- logcial AND of a list

Line: 119 to 119
 

Changed:
<
<

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
Changed:
<
<
>
>

EVEN( num ) -- test for even number

 

EXACT( text1, text2 ) -- compare two text strings

Line: 133 to 139
 
  • Example: %CALC{"$EXACT(foo, $LOWER(Foo))"}% returns 1
  • Related: $IF(), $TRIM()
Added:
>
>

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.
Line: 144 to 166
 

FORMAT( type, prec, number ) -- format a number to a certain type and precision

Changed:
<
<
  • 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
Added:
>
>
  • 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()
Line: 171 to 197
 
  • 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
Changed:
<
<
>
>
 

IF( condition, value if true, value if 0 ) -- return a value based on a condition

Line: 206 to 232
 
  • 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 |
Changed:
<
<
>
>
 

LISTIF( condition, list ) -- remove elements from a list that do not meet a condition

Line: 225 to 251
 
Added:
>
>

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
Line: 242 to 275
 

LISTSIZE( list ) -- number of elements in a list

  • Syntax: $LISTSIZE( list )
  • Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
Changed:
<
<
>
>
 

LISTSORT( list ) -- sort a list

Line: 267 to 300
 

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())"}%
Changed:
<
<
>
>
 

MEDIAN( list ) -- median of a list or range of cells

  • Syntax: $MEDIAN( list )
  • Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
Changed:
<
<
>
>
 

MIN( list ) -- smallest value of a list or range of cells

  • Syntax: $MIN( list )
  • Example: %CALC{"$MIN(15, 3, 28)"}% returns 3
Changed:
<
<
>
>
 

MOD( num, divisor ) -- reminder after dividing num by divisor

  • Syntax: $MOD( num, divisor )
  • Example: %CALC{"$MOD(7, 3)"}% returns 1
Changed:
<
<
>
>

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

Line: 299 to 339
 
Added:
>
>

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()
Added:
>
>

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

  • Syntax: $PRODUCT( list )
Line: 312 to 365
 

Changed:
<
<

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
Line: 323 to 376
 

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 )
Changed:
<
<
  • 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
 

Line: 378 to 431
 

SET( name, value ) -- set a variable for later use

Changed:
<
<
  • 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
Changed:
<
<
>
>
 

SETM( name, formula ) -- update an existing variable based on a formula

Line: 395 to 448
 
  • Returns -1 if num is negative, 0 if zero, or 1 if positive
  • Syntax: $SIGN( num )
  • Example: %CALC{"$SIGN(-12.5)"}% returns -1
Changed:
<
<
>
>
 

SUBSTITUTE( text, old, new, instance, option ) -- substitute text

Line: 423 to 476
 

SUMPRODUCT( list, list ) -- scalar product on ranges of cells

  • Syntax: $SUMPRODUCT( list, list, list... )
Changed:
<
<
  • 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))
 

Line: 451 to 504
 

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 )
Changed:
<
<
  • 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
 

Line: 532 to 584
 
  • Debug plugin: (See output in data/debug.txt)
    • Set DEBUG = 0
Changed:
<
<
  • 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)
 
    • Set SKIPINCLUDE = 1

Line: 551 to 603
 
data/TWiki/SpreadSheetPlugin.txt Plugin topic
data/TWiki/SpreadSheetPlugin.txt,v Plugin topic repository
lib/TWiki/Plugins/SpreadSheetPlugin.pm Plugin Perl module
Added:
>
>
  • (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 Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 17 Jul 2004
>
>
Plugin Version: 17 Jun 2005 (1.018)
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
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
Line: 572 to 630
 
13 Oct 2003: Added $MULT(), contributed by TWiki:Main/GerritJanBaarda
30 Jul 2003: Added $TRANSLATE()
19 Jul 2003: Added $FIND(), $NOP(), $REPLACE(), $SEARCH(), $SUBSTITUTE(), contributed by TWiki:Main/PaulineCheung
Changed:
<
<
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
Changed:
<
<
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
Changed:
<
<
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()
 
CPAN Dependencies: none
TWiki:Plugins/Benchmark: GoodStyle 99%, FormattedSearch 99%, SpreadSheetPlugin 95%
Other Dependencies: none
Line: 592 to 650
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 17 Jul 2004
>
>
-- TWiki:Main/PeterThoeny - 17 Jun 2005
 

Revision 102004-07-17 - PeterThoeny

Line: 1 to 1
 

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.

Line: 411 to 411
 

SUM( list ) -- sum of a list or range of cells

  • Syntax: $SUM( list )
  • Example: To sum up column 5 excluding the title row, write %CALC{"$SUM(R2:C5..R$ROW(-1):C5)"}% in the last row; or simply %CALC{"$SUM($ABOVE())"}%
Changed:
<
<
>
>
 

SUMDAYS( list ) -- sum the days in a list or range of cells

Line: 445 to 445
 
  • Serialized date is seconds since the Epoch, e.g. midnight, 01 Jan 1970. Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone
  • Syntax: $TIME( text )
  • Example: %CALC{"$TIME(2003/10/14 GMT)"}% returns 1066089600
Changed:
<
<
>
>
 

TIMEADD( serial, value, unit ) -- add a value to a serialized date

Line: 460 to 460
 
  • The unit is seconds if not specified; unit can be specified as in $TIMEADD(). Note: An approximation is used for month and year calculations. Use $FORMAT() or $INT() to format real numbers
  • Syntax: $TIMEDIFF( serial_1, serial_2, unit )
  • Example: %CALC{"$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)"}% returns 1.5
Changed:
<
<
>
>
 

TODAY( ) -- serialized date of today at midnight GMT

Line: 491 to 491
 
  • Example: %CALC{"$VALUE(Total: -12.5)"}% returns -12.5
  • Related: $EVAL(), $INT()
Added:
>
>

WORKINGDAYS( serial_1, serial_2 ) -- working days between two serialized dates

  • Working days are Monday through Friday (sorry, Israel!)
  • Syntax: $WORKINGDAYS( serial_1, serial_2 )
  • Example: %CALC{"$WORKINGDAYS($TIME(2004/07/15), $TIME(2004/08/03))"}% returns 13
  • Related: $SUMDAYS(), $TIME(), $TIMEDIFF()
 

Bug Tracking Example

Bug#: Priority: Subject: Status: Days to fix
Line: 549 to 556
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 24 May 2004
>
>
Plugin Version: 17 Jul 2004
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
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
21 Mar 2004: Added $LISTITEM(); fixed call to unofficial function
Line: 584 to 592
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 24 May 2004 `
>
>
-- TWiki:Main/PeterThoeny - 17 Jul 2004
 

Revision 92004-05-25 - PeterThoeny

Line: 1 to 1
Changed:
<
<

TWiki Spreadsheet Plugin

>
>

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.
Line: 19 to 19
 
Changed:
<
<
Formula: %CALC{""}%  
Result:     guest
>
>
Formula: %CALC{"TWikiGuest)" />"}%  
Result:     TWiki Guest
 
Deleted:
<
<
 
Deleted:
<
<
 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.)
Deleted:
<
<
 
Added:
>
>
On this page:
 

Syntax Rules

Line: 51 to 49
 

Built-in Functions

Changed:
<
<
Function Description
"$ABOVE()" The address range of cells above the current cell
"$ABS(num)" The absolute value of a number. Example: %CALC{"$ABS(-12.5)"}% returns 12.5
"$AND(list)" The logcial AND of a list. Example: %CALC{"$AND(1, 0, 1)"}% returns 0
"$AVERAGE(list)" The average of a list or a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
"$CODE(text)" The ASCII numeric value of the first character in text. Example: %CALC{"$CODE(abc)"}% returns 97
"$COLUMN(offset)" The current column number with an optional offset
"$COUNTITEMS(list)" Counts individual items in a list. Example: %CALC{"$COUNTITEMS( $ABOVE() )"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
"$COUNTSTR(list, str)" Counts the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list. Example: To count the number of non empty cells above the current cell, write %CALC{"$COUNTSTR( $ABOVE() )"}%; to count the number of cells equal to DONE, write %CALC{"$COUNTSTR( $ABOVE(), DONE )"}%;
"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
"$FIND(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_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. Examples:
%CALC{"$FIND(f, fluffy)"}% returns 1
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
%CALC{"$FIND(@, fluffy, 1)"}% returns 0
"$FORMAT(type, prec, number)" Formats a number to a certain type and precision. Types with examples:
  - %CALC{"$FORMAT( COMMA, 2, 12345.6789 )"}% returns 12,345.68
  - %CALC{"$FORMAT( DOLLAR, 2, 12345.67 )"}% returns $12,345.68
  - %CALC{"$FORMAT( NUMBER, 1, 12345.67 )"}% returns 12345.7
  - %CALC{"$FORMAT( PERCENT, 1, 0.1234567 )"}% returns 12.3%
"$FORMATTIME(serial, text)" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
"$FORMATGMTIME(serial, text)" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. 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. See also $SET(). Example: %CALC{"$GET(my_total)"}% returns the value of the my_total variable
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:
%CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK)"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2))"}% returns the content of R1:C2 or empty if empty
%CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2)))"}% sets a variable conditionally
"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT(10 / 4)"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
"$LISTIF(condition, list)" Remove elements from a list that do not meet a condition. In addition to the condition described in $IF(), you can use $item to indicate the current element, and $index for the list index, starting at 1. Examples:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , E)"}% returns non-empty elements A, B, E
%CALC{"$LISTIF($index > 2, A, B, C, D)"}% returns C, D
"$LISTITEM(index, list)" Get one element of a list. Index is 1 to size of list; use a negative number to count from the end of the list. Examples:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
"$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. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
"$LISTSORT(list)" Sorts a list in ASCII order, or numerically if all elements are numeric. Example: %CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
"$LISTUNIQUE(list)" Removes all duplicates from a list. Example: %CALC{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"}% returns Apple, Orange, Kiwi
"$LOWER(text)" The lower case string of a text. Example: %CALC{"$LOWER( $T(R1:C5) )"}% returns the lower case string of the text in cell R1:C5
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
"$MIN(list)" The smallest value of a list or range of cells. Example: %CALC{"$MIN(15, 3, 28)"}% returns 3
"$MOD(num, divisor)" The reminder after dividing num by divisor. Example: %CALC{"$MOD(7, 3)"}% returns 1
"$NOP(text)" A no-operation. Allows one to defy the order of Plugin execution. For example, it will allow preprossing to be done before %SEARCH{}% is evaluated. Use $per to escape '%'.
"$NOT(num)" The reverse logic of a number. Returns 0 if num is not zero, 1 if zero. Example: %CALC{"$NOT(0)"}% returns 1
"$OR(list)" The logcial OR of a list. Example: %CALC{"$OR(1, 0, 1)"}% returns 1
"$PRODUCT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh"}% returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh
"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
"$RIGHT()" The address range of cells to the right of the current cell
"$ROUND(formula, digits)" 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. Examples:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
%CALC{"$ROUND(34.9, -1)"}% returns 30
"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns 0
"$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. See also $GET(). 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)" Updates an existing variable based on a formula. Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables. Example: %CALC{"$SETM( total, + $SUM($LEFT()) )"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1
"$SUBSTITUTE(text, old, new, instance, option)" Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r. See also $REPLACE(), $TRANSLATE(). Examples:
%CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
"$SUM(list)" The sum of a list or range of cells. Example: To sum up column 5 excluding the title row, write: %CALC{"$SUM( R2:C5..R$ROW(-1):C5 )"}% in the last row; or simply %CALC{"$SUM( $ABOVE() )"}%
"$SUMDAYS(list)" The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours. Example: %CALC{"$SUMDAYS( 2w, 1, 2d, 4h )"}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
"$SUMPRODUCT(list, list, ...)" The scalar product on ranges of cells. Example: %CALC{"$SUM( R2:C1..R4:C1, R2:C5..R4:C5 )"}% evaluates and returns ($T(R2:C1) * $T(R2:C5) + $T(R3:C1) * $T(R3:C5) + $T(R4:C1) * $T(R4:C5))
"$T(address)" The content of a cell. Example: %CALC{"$T(R1:C5)"}% returns the text in cell R1:C5
"$TRANSLATE(text, from, to)" Translate text from a set of characters to another set, one character by one. The text may contain commas; the last two comma separated parameters are required. For from and to parameters, you can write $comma to escape comma, $sp to escape space. See also $REPLACE(), $SUBSTITUTE(). Examples:
%CALC{"$TRANSLATE(boom,bm,cl)"}% returns cool
%CALC{"$TRANSLATE(one, two,$comma,;)"}% returns one; two
"$TIME(text)" Converts a date string into a serialized date number (seconds since the Epoch, e.g. midnight, 01 Jan 1970). Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TIME( 2003/10/14 GMT )"}% returns 1066089600
"$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. See also $TIME(), $TIMEDIFF(), $TODAY(), $FORMATTIME(). Example: %CALC{"$TIMEADD( $TIME(), 2, week )"}% returns the serialized date two weeks from now
"$TIMEDIFF( serial_1, serial_2, unit )" Time difference between two serialized dates. The unit is seconds if not specified; unit can be specified as in $TIMEADD(). Note: An approximation is used for month and year calculations. Use $FORMAT() or $INT() to format real numbers. See also $TIME(), $TIMEADD(), $TODAY(), $FORMATTIME(). Example: %CALC{"$TIMEDIFF( $TIME(), $EVAL($TIME()+90), minute )"}% returns 1.5
"$TODAY()" Get the serialized date of today at midnight GMT. The related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT. See also $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
"$TRIM(text)" Removes all spaces from text except for single spaces between words. Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces.
"$UPPER(text)" The upper case string of a text. Example: %CALC{"$UPPER( $T(R1:C5) )"}% returns the upper case string of the text in cell R1:C5
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:
%CALC{"$VALUE(US$1,200)"}% returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
%CALC{"$VALUE(Total: -12.5)"}% returns -12.5
>
>
Conventions for Syntax:
  • Required parameters are indicated in ( bold )
  • Optional parameters are indicated in ( bold italic )

ABOVE( ) -- address range of cells above the current cell

  • Syntax: $ABOVE( )
  • Example: %CALC{"$SUM($ABOVE())"}% returns the sum of cells above the current cell
  • Related: $LEFT(), $RIGHT()

ABS( num ) -- absolute value of a number

  • Syntax: $ABS( num )
  • Example: %CALC{"$ABS(-12.5)"}% returns 12.5
  • Related: $SIGN()

AND( list ) -- logcial AND of a list

  • Syntax: $AND( list )
  • Example: %CALC{"$AND(1, 0, 1)"}% returns 0
  • Related: $NOT(), $IF(), $OR()

AVERAGE( list ) -- average of a list or a range of cells

  • Syntax: $AVERAGE( list )
  • Example: %CALC{"$AVERAGE(R2:C5..R$ROW(-1):C5)"}% returns the average of column 5, excluding the title row
  • Related: $LIST(), $MAX(), $MEDIAN(), $MIN()

CHAR( number ) -- ASCII character represented by number

  • Syntax: $CHAR( number )
  • Example: Example: %CALC{"$CHAR(97)"}% returns a
  • Related: $CODE()

CODE( text ) -- ASCII numeric value of character

  • The ASCII numeric value of the first character in text
  • Syntax: $CODE( text )
  • Example: %CALC{"$CODE(abc)"}% returns 97
  • Related: $CHAR()

COLUMN( offset ) -- current column number

  • The current table column number with an optional offset
  • Syntax: $COLUMN( offset )
  • Example: %CALC{"$COLUMN()"}% returns 2 for the second column
  • Related: $ROW(), $T()

COUNTITEMS( list ) -- count individual items in a list

  • Syntax: $COUNTITEMS( list )
  • Example: %CALC{"$COUNTITEMS($ABOVE())"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
  • Related: $COUNTSTR(), $LIST()

COUNTSTR( list, str ) -- count the number of cells in a list equal to a given string

  • Count the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list
  • Syntax: $COUNTSTR( list, str )
  • Example: %CALC{"$COUNTSTR($ABOVE())"}% counts the number of non empty cells above the current cell
  • Example: %CALC{"$COUNTSTR($ABOVE(), DONE)"}% counts the number of cells equal to DONE
  • Related: $COUNTITEMS(), $LIST()

DEF( list ) -- find first non-empty list item or cell

  • Returns the first list item or cell reference that is not empty
  • Syntax: $DEF( list )
  • Example: %CALC{"$DEF(R1:C1..R1:C3)"}%
  • Related: $COUNTSTR(), $LISTIF(), $LIST()

EVAL( formula ) -- evaluate a simple 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
  • Related: $INT(), $MOD(), $ROUND(), $VALUE()

EXACT( text1, text2 ) -- compare two text strings

  • Compares two text strings and returns 1 if they are exactly the same, or 0 if not
  • Syntax: $EXACT( text1, text2 )
  • Example: %CALC{"$EXACT(foo, Foo)"}% returns 0
  • Example: %CALC{"$EXACT(foo, $LOWER(Foo))"}% returns 1
  • Related: $IF(), $TRIM()

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.
  • Syntax: $FIND( string, text, start )
  • Example: %CALC{"$FIND(f, fluffy)"}% returns 1
  • Example: %CALC{"$FIND(f, fluffy, 2)"}% returns 4
  • Example: %CALC{"$FIND(@, fluffy, 1)"}% returns 0
  • Related: $REPLACE(), $SEARCH()

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
  • 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(NUMBER, 1, 12345.67)"}% returns 12345.7
  • Example: %CALC{"$FORMAT(PERCENT, 1, 0.1234567)"}% returns 12.3%
  • Related: $ROUND()

FORMATTIME( serial, text ) -- convert a serialized date into a date string

  • The following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone.
  • Syntax: $FORMATTIME( serial, text )
  • Example: %CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
  • Related: $FORMATGMTIME(), $TIME(), $TIMEADD(), $TIMEDIFF(), $TODAY()

FORMATGMTIME( serial, text ) -- convert a serialized date into a GMT date string

  • The date string represents the time in Greenwich time zone. Same variable expansion as in $FORMATTIME().
  • Syntax: $FORMATGMTIME( serial, text )
  • Example: %CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
  • Related: $FORMATTIME(), $TIME(), $TIMEADD(), $TIMEDIFF(), $TODAY()

GET( name ) -- get the value of a previously set variable

  • 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
  • Related: $SET(), $SETM()

IF( condition, value if true, value if 0 ) -- return a value based on a condition

  • The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than).
  • Syntax: $IF( condition, value if true, value if 0 )
  • 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
  • Related: $AND(), $EXACT(), $LISTIF(), $NOT(), $OR()

INT( formula ) -- evaluate formula and round down to nearest integer

  • Addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted
  • Syntax: $INT( formula )
  • Example: %CALC{"$INT(10 / 4)"}% returns 2
  • Related: $EVAL(), $ROUND(), $VALUE()

LEFT( ) -- address range of cells to the left of the current cell

  • Syntax: $LEFT( )
  • Example: %CALC{"$SUM($LEFT())"}% returns the sum of cells to the left of the current cell
  • Related: $ABOVE(), $RIGHT()

LENGTH( text ) -- length of text in bytes

  • Syntax: $LENGTH( text )
  • Example: %CALC{"$LENGTH(abcd)"}% returns 4
  • Related: $LISTSIZE()

LIST( range ) -- convert content of a cell range into a list

LISTIF( condition, list ) -- remove elements from a list that do not meet a condition

  • In addition to the condition described in $IF(), you can use $item to indicate the current element, and $index for the list index, starting at 1
  • Syntax: $LISTIF( condition, list )
  • 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: $IF(), $LIST(), $LISTITEM(), $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SUM()

LISTITEM( index, list ) -- get one element of a list

LISTMAP( formula, list ) -- evaluate and update each element of a list

LISTREVERSE( list ) -- opposite order of a list

LISTSIZE( list ) -- number of elements in a list

LISTSORT( list ) -- sort a list

LISTUNIQUE( list ) -- remove all duplicates from a list

LOWER( text ) -- lower case string of a text

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())"}%
  • Related: $LIST(), $MEDIAN(), $MIN()

MEDIAN( list ) -- median of a list or range of cells

  • Syntax: $MEDIAN( list )
  • Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
  • Related: $LIST(), $MAX(), $MIN()

MIN( list ) -- smallest value of a list or range of cells

MOD( num, divisor ) -- reminder after dividing num by divisor

  • Syntax: $MOD( num, divisor )
  • Example: %CALC{"$MOD(7, 3)"}% returns 1
  • Related: $EVAL(), $()

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
  • Syntax: $NOP( text )

NOT( num ) -- reverse logic of a number

  • Returns 0 if num is not zero, 1 if zero
  • Syntax: $NOT( num )
  • Example: %CALC{"$NOT(0)"}% returns 1
  • Related: $AND(), $IF(), $OR()

OR( list ) -- logcial OR of a list

  • Syntax: $OR( list )
  • Example: %CALC{"$OR(1, 0, 1)"}% returns 1
  • Related: $AND(), $IF(), $NOT()

PRODUCT( list ) -- product of a list or range of cells

  • Syntax: $PRODUCT( list )
  • Example: To calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
  • Related: $LIST(), $PRODUCT(), $SUM(), $SUMPRODUCT()

PROPER( text ) -- properly capitalize trxt

  • 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
  • Example: %CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula-1)
  • Related: $LOWER(), $PROPERSPACE(), $TRIM(), $UPPER()

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
  • Related: $LOWER(), $PROPER(), $TRIM(), $UPPER()

RAND( max ) -- random number

  • Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified
  • Syntax: $RAND( max )
  • Related: $EVAL()

REPEAT(text) -- repeat text a number of times

  • Syntax: $REPEAT( text )
  • Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\

REPLACE( text, start, num, new ) -- replace part of a text string

  • 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
  • Related: $FIND(), $SEARCH(), $SUBSTITUTE(), $TRANSLATE()

RIGHT( ) -- address range of cells to the right of the current cell

  • Syntax: $RIGHT( )
  • Example: %CALC{"$SUM($RIGHT())"}% returns the sum of cells to the right of the current cell
  • Related: $ABOVE(), $LEFT()

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
  • Syntax: $ROUND( formula, digits )
  • Example: %CALC{"$ROUND(3.15, 1)"}% returns 3.2
  • Example: %CALC{"$ROUND(3.149, 1)"}% returns 3.1
  • Example: %CALC{"$ROUND(-2.475, 2)"}% returns -2.48
  • Example: %CALC{"$ROUND(34.9, -1)"}% returns 30
  • Related: $INT(), $FORMAT()

ROW( offset ) -- current row number

  • The current table row number with an optional offset
  • Syntax: $ROW( offset )
  • Example: To get the number of rows excluding table heading (first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
  • Related: $COLUMN(), $T()

SEARCH( string, text, start ) -- search a string within a text

  • 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 a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched
  • Syntax: $SEARCH( string, text, start )
  • Example: %CALC{"$SEARCH([uy], fluffy)"}% returns 3
  • Example: %CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
  • Example: %CALC{"$SEARCH([abc], fluffy,)"}% returns 0
  • Related: $FIND(), $REPLACE()

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
  • 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
  • Related: $GET(), SETM()

SETM( name, formula ) -- update an existing variable based on a formula

  • Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables
  • Syntax: $SETM( name, formula )
  • Example: %CALC{"$SETM(total, + $SUM($LEFT()))"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
  • Related: $GET(), $SET()

SIGN( num ) -- sign of a number

  • Returns -1 if num is negative, 0 if zero, or 1 if positive
  • Syntax: $SIGN( num )
  • Example: %CALC{"$SIGN(-12.5)"}% returns -1
  • Related: $ABS(), $EVAL(), $INT(), $NOT()

SUBSTITUTE( text, old, new, instance, option ) -- substitute text

  • Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r
  • Syntax: $SUBSTITUTE( text, old, new, instance, option )
  • Example: %CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
  • 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
  • Related: $REPLACE(), $TRANSLATE()

SUM( list ) -- sum of a list or range of cells

  • Syntax: $SUM( list )
  • Example: To sum up column 5 excluding the title row, write %CALC{"$SUM(R2:C5..R$ROW(-1):C5)"}% in the last row; or simply %CALC{"$SUM($ABOVE())"}%
  • Related: $LIST(), $PRODUCT(), $SUMPRODUCT()

SUMDAYS( list ) -- sum the days in a list or range of cells

  • The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours
  • Syntax: $SUMDAYS( list )
  • Example: %CALC{"$SUMDAYS(2w, 1, 2d, 4h)"}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
  • Related: $SUM(), $TIME(), $FORMATTIME()

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))
  • Related: $LIST(), $PRODUCT(), $SUM()

T( address ) -- content of a cell

  • Syntax: $T( address )
  • Example: %CALC{"$T(R1:C5)"}% returns the text in cell R1:C5
  • Related: $COLUMN(), $ROW()

TRANSLATE( text, from, to ) -- translate text from one set of characters to another

  • The translation is done from a set to a set, one character by one. The text may contain commas; all three parameters are required. In the from and to parameters you can write $comma to escape comma, $sp to escape space
  • Syntax: $TRANSLATE( text, from, to )
  • Example: %CALC{"$TRANSLATE(boom,bm,cl)"}% returns cool
  • Example: %CALC{"$TRANSLATE(one, two,$comma,;)"}% returns one; two
  • Related: $REPLACE(), $SUBSTITUTE()

TIME( text ) -- convert a date string into a serialized date number

  • Serialized date is seconds since the Epoch, e.g. midnight, 01 Jan 1970. Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone
  • Syntax: $TIME( text )
  • Example: %CALC{"$TIME(2003/10/14 GMT)"}% returns 1066089600
  • Related: $FORMATTIME(), $FORMATGMTIME(), $TIMEADD(), $TIMEDIFF(), $TODAY()

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
  • Related: $FORMATTIME(), $FORMATGMTIME(), $TIME(), $TIMEDIFF(), $TODAY()

TIMEDIFF( serial_1, serial_2, unit ) -- time difference between two serialized dates

  • The unit is seconds if not specified; unit can be specified as in $TIMEADD(). Note: An approximation is used for month and year calculations. Use $FORMAT() or $INT() to format real numbers
  • Syntax: $TIMEDIFF( serial_1, serial_2, unit )
  • Example: %CALC{"$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)"}% returns 1.5
  • Related: $FORMAT(), $FORMATTIME(), $FORMATGMTIME(), $INT(), $TIME(), $TIMEADD(), $TODAY()

TODAY( ) -- serialized date of today at midnight GMT

  • In contrast, the related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT
  • Syntax: $TODAY( )
  • Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
  • Related: $FORMATTIME(), $FORMATGMTIME(), $TIME(), $TIMEADD(), $TIMEDIFF()

TRIM( text ) -- trim spaces from text

  • Removes all spaces from text except for single spaces between words
  • Syntax: $TRIM( text )
  • Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces
  • Related: $EXACT(), $PROPERSPACE()

UPPER( text ) -- upper case string of a text

VALUE( text ) -- convert text to number

  • Extracts a number from text. Returns 0 if not found
  • Syntax: $VALUE( text )
  • Example: %CALC{"$VALUE(US$1,200)"}% returns 1200
  • Example: %CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
  • Example: %CALC{"$VALUE(Total: -12.5)"}% returns -12.5
  • Related: $EVAL(), $INT()
 

Bug Tracking Example

Line: 174 to 549
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 03 Apr 2004
>
>
Plugin Version: 24 May 2004
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
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
21 Mar 2004: Added $LISTITEM(); fixed call to unofficial function
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE()); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning
Line: 208 to 584
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 03 Apr 2004
>
>
-- TWiki:Main/PeterThoeny - 24 May 2004 `
 

Revision 82004-04-03 - PeterThoeny

Line: 1 to 1
 

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.

Changed:
<
<
Example:
>
>
Example:
 
Region: Sales:
Northeast 320
Line: 13 to 14
 
Asia 220
Total: 220
Added:
>
>
      Interactive example:

Formula: %CALC{""}%  
Result:     guest

 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.)
Added:
>
>
 

Syntax Rules

Line: 58 to 74
 
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
Changed:
<
<
"$LISTIF(condition, list)" Remove elements from a list that do not meet a condition. In addition to the condition described in $IF(), you can use $item to indicate the current element. Examples:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , C)"}% returns A, B, C
>
>
"$LISTIF(condition, list)" Remove elements from a list that do not meet a condition. In addition to the condition described in $IF(), you can use $item to indicate the current element, and $index for the list index, starting at 1. Examples:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , E)"}% returns non-empty elements A, B, E
%CALC{"$LISTIF($index > 2, A, B, C, D)"}% returns C, D
 
"$LISTITEM(index, list)" Get one element of a list. Index is 1 to size of list; use a negative number to count from the end of the list. Examples:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
"$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. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple

Revision 72004-04-03 - PeterThoeny

Line: 1 to 1
 

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.

Line: 37 to 37
 
Function Description
"$ABOVE()" The address range of cells above the current cell
Added:
>
>
"$ABS(num)" The absolute value of a number. Example: %CALC{"$ABS(-12.5)"}% returns 12.5
 
"$AND(list)" The logcial AND of a list. Example: %CALC{"$AND(1, 0, 1)"}% returns 0
"$AVERAGE(list)" The average of a list or a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
Line: 47 to 48
 
"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
Changed:
<
<
"$FIND(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_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; an empty string is returned if nothing is matched. Examples:
%CALC{"$FIND(f, fluffy)"}% returns 1
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
%CALC{"$FIND(@, fluffy, 1)"}% returns an empty string
>
>
"$FIND(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_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. Examples:
%CALC{"$FIND(f, fluffy)"}% returns 1
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
%CALC{"$FIND(@, fluffy, 1)"}% returns 0
 
"$FORMAT(type, prec, number)" Formats a number to a certain type and precision. Types with examples:
  - %CALC{"$FORMAT( COMMA, 2, 12345.6789 )"}% returns 12,345.68
  - %CALC{"$FORMAT( DOLLAR, 2, 12345.67 )"}% returns $12,345.68
  - %CALC{"$FORMAT( NUMBER, 1, 12345.67 )"}% returns 12345.7
  - %CALC{"$FORMAT( PERCENT, 1, 0.1234567 )"}% returns 12.3%
"$FORMATTIME(serial, text)" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
"$FORMATGMTIME(serial, text)" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
Line: 57 to 58
 
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
Changed:
<
<
"$LISTITEM(index, list)" Get one item of a list. Index is 1 to size of list; use a negative number to count from the end of the list. Examples:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
"$LISTMAP(formula, list)" Evaluate and update each element of a list. In the formla, $item indicates the element, $index the index of the list starting at 1. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
>
>
"$LISTIF(condition, list)" Remove elements from a list that do not meet a condition. In addition to the condition described in $IF(), you can use $item to indicate the current element. Examples:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , C)"}% returns A, B, C
"$LISTITEM(index, list)" Get one element of a list. Index is 1 to size of list; use a negative number to count from the end of the list. Examples:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
"$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. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
 
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
"$LISTSORT(list)" Sorts a list in ASCII order, or numerically if all elements are numeric. Example: %CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
Line: 80 to 82
 
"$RIGHT()" The address range of cells to the right of the current cell
"$ROUND(formula, digits)" 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. Examples:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
%CALC{"$ROUND(34.9, -1)"}% returns 30
"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
Changed:
<
<
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns an empty string
>
>
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns 0
 
"$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. See also $GET(). 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)" Updates an existing variable based on a formula. Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables. Example: %CALC{"$SETM( total, + $SUM($LEFT()) )"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1
Line: 156 to 158
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 21 Mar 2004
>
>
Plugin Version: 03 Apr 2004
 
Change History:
<-- specify latest version first -->
 
Changed:
<
<
21 Mar 2004: Added $LISTINDEX(); fixed call to inofficial function
>
>
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
21 Mar 2004: Added $LISTITEM(); fixed call to unofficial function
 
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE()); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning
08 Mar 2004: Added $LIST()
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
Line: 189 to 192
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 21 Mar 2004
>
>
-- TWiki:Main/PeterThoeny - 03 Apr 2004

Revision 62004-03-21 - PeterThoeny

Line: 1 to 1
 

TWiki Spreadsheet Plugin

Changed:
<
<
This Plugin adds speadsheet capabilities to TWiki topics. Formulas like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables.
>
>
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.
  Example:
Line: 18 to 18
 

Syntax Rules

Changed:
<
<
  • The formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
>
>
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) )"}%
  • Functions are evaluated from left to right, and from inside to outside if nested
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
Line: 56 to 57
 
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
Added:
>
>
"$LISTITEM(index, list)" Get one item of a list. Index is 1 to size of list; use a negative number to count from the end of the list. Examples:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
 
"$LISTMAP(formula, list)" Evaluate and update each element of a list. In the formla, $item indicates the element, $index the index of the list starting at 1. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
Line: 71 to 73
 
"$OR(list)" The logcial OR of a list. Example: %CALC{"$OR(1, 0, 1)"}% returns 1
"$PRODUCT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
Changed:
<
<
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(McIntosh likes WikiWord links like WebHome and [[WebHome][WebHome]])"}% returns McIntosh likes Wiki Word links like Web Home and Web Home
>
>
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh"}% returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh
 
"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
Line: 135 to 137
 
  • WikiWords to exclude from being spaced out by the $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
Changed:
<
<
>
>
 
Line: 154 to 156
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 16 Mar 2004
>
>
Plugin Version: 21 Mar 2004
 
Change History:
<-- specify latest version first -->
 
Changed:
<
<
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE(); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning
>
>
21 Mar 2004: Added $LISTINDEX(); fixed call to inofficial function
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE()); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning
 
08 Mar 2004: Added $LIST()
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
27 Feb 2004: Added $COUNTUNIQUE()
Line: 186 to 189
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 16 Mar 2004
>
>
-- TWiki:Main/PeterThoeny - 21 Mar 2004

Revision 52004-03-16 - PeterThoeny

Line: 1 to 1
 

TWiki Spreadsheet Plugin

This Plugin adds speadsheet capabilities to TWiki topics. Formulas like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables.

Line: 43 to 43
 
"$COLUMN(offset)" The current column number with an optional offset
"$COUNTITEMS(list)" Counts individual items in a list. Example: %CALC{"$COUNTITEMS( $ABOVE() )"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
"$COUNTSTR(list, str)" Counts the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list. Example: To count the number of non empty cells above the current cell, write %CALC{"$COUNTSTR( $ABOVE() )"}%; to count the number of cells equal to DONE, write %CALC{"$COUNTSTR( $ABOVE(), DONE )"}%;
Deleted:
<
<
"$COUNTUNIQUE(list)" Counts unique items in a list, separated by comma and/or space. Example: %CALC{"$COUNTUNIQUE( $ABOVE() )"}% returns Alice: 2, Mike: 1, Tom: 2 assuming the cells above the current cell contain Alice and Tom, Mike and Alice, Tom
 
"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
Line: 52 to 51
 
"$FORMATTIME( serial, text )" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME( 0, $year/$month/$day GMT )"}% returns 1970/01/01 GMT
"$FORMATGMTIME( serial, text )" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME( 1041379200, $day $mon $year )"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. 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. See also $SET(). Example: %CALC{"$GET( my_total )"}% returns the value of the my_total variable
Changed:
<
<
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:
%CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2) )"}% returns the content of R1:C2 or empty if empty
%CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2) ))"}% sets a variable conditionally (notice that you cannot set a variable conditionally inside an $IF() since formulae in the "value if true" and "value if 0" are both evaluated before the condition is applied)
>
>
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:
%CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2) )"}% returns the content of R1:C2 or empty if empty
%CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2) ))"}% sets a variable conditionally
 
"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Changed:
<
<
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
>
>
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
"$LISTMAP(formula, list)" Evaluate and update each element of a list. In the formla, $item indicates the element, $index the index of the list starting at 1. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
"$LISTSORT(list)" Sorts a list in ASCII order, or numerically if all elements are numeric. Example: %CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
"$LISTUNIQUE(list)" Removes all duplicates from a list. Example: %CALC{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"}% returns Apple, Orange, Kiwi
 
"$LOWER(text)" The lower case string of a text. Example: %CALC{"$LOWER( $T(R1:C5) )"}% returns the lower case string of the text in cell R1:C5
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
Line: 76 to 80
 
"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns an empty string
"$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. See also $GET(). 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
Added:
>
>
"$SETM(name, formula)" Updates an existing variable based on a formula. Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables. Example: %CALC{"$SETM( total, + $SUM($LEFT()) )"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
 
"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1
"$SUBSTITUTE(text, old, new, instance, option)" Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r. See also $REPLACE(), $TRANSLATE(). Examples:
%CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
"$SUM(list)" The sum of a list or range of cells. Example: To sum up column 5 excluding the title row, write: %CALC{"$SUM( R2:C5..R$ROW(-1):C5 )"}% in the last row; or simply %CALC{"$SUM( $ABOVE() )"}%
Line: 149 to 154
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 08 Mar 2004
>
>
Plugin Version: 16 Mar 2004
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE(); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning
 
08 Mar 2004: Added $LIST()
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
27 Feb 2004: Added $COUNTUNIQUE()
Line: 180 to 186
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 08 Mar 2004
>
>
-- TWiki:Main/PeterThoeny - 16 Mar 2004

Revision 42004-03-09 - PeterThoeny

Line: 1 to 1
 

TWiki Spreadsheet Plugin

This Plugin adds speadsheet capabilities to TWiki topics. Formulas like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables.

Line: 56 to 56
 
"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Added:
>
>
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
 
"$LOWER(text)" The lower case string of a text. Example: %CALC{"$LOWER( $T(R1:C5) )"}% returns the lower case string of the text in cell R1:C5
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
Line: 68 to 69
 
"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(McIntosh likes WikiWord links like WebHome and [[WebHome][WebHome]])"}% returns McIntosh likes Wiki Word links like Web Home and Web Home
"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
Changed:
<
<
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(Hi! , 3)"}% returns Hi! Hi! Hi!
>
>
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
 
"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
"$RIGHT()" The address range of cells to the right of the current cell
"$ROUND(formula, digits)" 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. Examples:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
%CALC{"$ROUND(34.9, -1)"}% returns 30
Line: 88 to 89
 
"$TODAY()" Get the serialized date of today at midnight GMT. The related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT. See also $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
"$TRIM(text)" Removes all spaces from text except for single spaces between words. Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces.
"$UPPER(text)" The upper case string of a text. Example: %CALC{"$UPPER( $T(R1:C5) )"}% returns the upper case string of the text in cell R1:C5
Changed:
<
<
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:
%CALC{"$VALUE(US$1,200)"}% returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
%CALC{"$VALUE(Total: -12.5)"}% returns 12.5
>
>
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:
%CALC{"$VALUE(US$1,200)"}% returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
%CALC{"$VALUE(Total: -12.5)"}% returns -12.5
 

Bug Tracking Example

Line: 148 to 149
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 06 Mar 2004
>
>
Plugin Version: 08 Mar 2004
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
08 Mar 2004: Added $LIST()
 
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
27 Feb 2004: Added $COUNTUNIQUE()
24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
Line: 178 to 180
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 06 Mar 2004
>
>
-- TWiki:Main/PeterThoeny - 08 Mar 2004

Revision 32004-03-07 - PeterThoeny

Line: 1 to 1
 

TWiki Spreadsheet Plugin

This Plugin adds speadsheet capabilities to TWiki topics. Formulas like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables.

Line: 20 to 20
 
  • The formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
Changed:
<
<
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
>
>
  • Functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
  • Functions are evaluated from left to right, and from inside to outside if nested
 
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. %CALC{"$SUM( 3, 5, 7 )"}%
  • A table cell can be addressed as R1:C1. Table address matrix:
Line: 35 to 36
 
Function Description
"$ABOVE()" The address range of cells above the current cell
Changed:
<
<
"$AVERAGE(list)" The average of the content of a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
>
>
"$AND(list)" The logcial AND of a list. Example: %CALC{"$AND(1, 0, 1)"}% returns 0
"$AVERAGE(list)" The average of a list or a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
 
"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
"$CODE(text)" The ASCII numeric value of the first character in text. Example: %CALC{"$CODE(abc)"}% returns 97
"$COLUMN(offset)" The current column number with an optional offset
Line: 50 to 52
 
"$FORMATTIME( serial, text )" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME( 0, $year/$month/$day GMT )"}% returns 1970/01/01 GMT
"$FORMATGMTIME( serial, text )" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME( 1041379200, $day $mon $year )"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. 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. See also $SET(). Example: %CALC{"$GET( my_total )"}% returns the value of the my_total variable
Changed:
<
<
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Example: %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
>
>
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:
%CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2) )"}% returns the content of R1:C2 or empty if empty
%CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2) ))"}% sets a variable conditionally (notice that you cannot set a variable conditionally inside an $IF() since formulae in the "value if true" and "value if 0" are both evaluated before the condition is applied)
 
"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Line: 58 to 60
 
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN( 3, 9, 4, 5 )"}% returns 4.5
"$MIN(list)" The smallest value of a list or range of cells. Example: %CALC{"$MIN( 15, 3, 28 )"}% returns 3
Changed:
<
<
"$MULT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$MULT($LEFT())"}%
>
>
"$MOD(num, divisor)" The reminder after dividing num by divisor. Example: %CALC{"$MOD(7, 3)"}% returns 1
 
"$NOP(text)" A no-operation. Allows one to defy the order of Plugin execution. For example, it will allow preprossing to be done before %SEARCH{}% is evaluated. Use $per to escape '%'.
Added:
>
>
"$NOT(num)" The reverse logic of a number. Returns 0 if num is not zero, 1 if zero. Example: %CALC{"$NOT(0)"}% returns 1
"$OR(list)" The logcial OR of a list. Example: %CALC{"$OR(1, 0, 1)"}% returns 1
"$PRODUCT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(McIntosh likes WikiWord links like WebHome and [[WebHome][WebHome]])"}% returns McIntosh likes Wiki Word links like Web Home and Web Home
"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(Hi! , 3)"}% returns Hi! Hi! Hi!
 
"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
"$RIGHT()" The address range of cells to the right of the current cell
Changed:
<
<
"$ROUND(formula)" Evaluates a simple formula and rounds the result up or down to the nearest integer. Example: %CALC{"$INT( 10 / 6 )"}% returns 2
>
>
"$ROUND(formula, digits)" 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. Examples:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
%CALC{"$ROUND(34.9, -1)"}% returns 30
 
"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns an empty string
"$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. See also $GET(). 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
Added:
>
>
"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1
 
"$SUBSTITUTE(text, old, new, instance, option)" Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r. See also $REPLACE(), $TRANSLATE(). Examples:
%CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
"$SUM(list)" The sum of a list or range of cells. Example: To sum up column 5 excluding the title row, write: %CALC{"$SUM( R2:C5..R$ROW(-1):C5 )"}% in the last row; or simply %CALC{"$SUM( $ABOVE() )"}%
"$SUMDAYS(list)" The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours. Example: %CALC{"$SUMDAYS( 2w, 1, 2d, 4h )"}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
Line: 78 to 88
 
"$TODAY()" Get the serialized date of today at midnight GMT. The related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT. See also $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
"$TRIM(text)" Removes all spaces from text except for single spaces between words. Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces.
"$UPPER(text)" The upper case string of a text. Example: %CALC{"$UPPER( $T(R1:C5) )"}% returns the upper case string of the text in cell R1:C5
Added:
>
>
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:
%CALC{"$VALUE(US$1,200)"}% returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
%CALC{"$VALUE(Total: -12.5)"}% returns 12.5
 

Bug Tracking Example

Line: 102 to 113
  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.
Changed:
<
<

SpreadSheetPlugin Settings

>
>

Plugin Settings

  Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
Line: 116 to 127
 
  • Do not handle %CALC{}% tag in included topic while including topic: (default: 1)
    • Set SKIPINCLUDE = 1
Added:
>
>
  • WikiWords to exclude from being spaced out by the $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
    • Set DONTSPACE = CodeWarrior, McIntosh, RedHat, SuSE
 

Plugin Installation Instructions

Line: 132 to 148
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 27 Feb 2004
>
>
Plugin Version: 06 Mar 2004
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
 
27 Feb 2004: Added $COUNTUNIQUE()
24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
21 Oct 2003: Added support for lists (1, 2, 3) and lists of table ranges (R1:C1..R1:C5, R3:C1..R3:C5) for all functions that accept a table range; added $TIMEADD(); in $TIMEDIFF() added week unit; in $FORMATTIME() changed $weekday to $wd and added $wday and $weekday
Line: 161 to 178
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 27 Feb 2004
>
>
-- TWiki:Main/PeterThoeny - 06 Mar 2004

Revision 22004-02-28 - PeterThoeny

Line: 1 to 1
 

TWiki Spreadsheet Plugin

This Plugin adds speadsheet capabilities to TWiki topics. Formulas like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables.

Line: 20 to 20
 
  • The formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
Changed:
<
<
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COL(0)..R$ROW(-1):C$COL(0) )"}%
>
>
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
 
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. %CALC{"$SUM( 3, 5, 7 )"}%
  • A table cell can be addressed as R1:C1. Table address matrix:
Line: 39 to 39
 
"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
"$CODE(text)" The ASCII numeric value of the first character in text. Example: %CALC{"$CODE(abc)"}% returns 97
"$COLUMN(offset)" The current column number with an optional offset
Changed:
<
<
"$COUNTITEMS(list)" The count of individual items in a list. Example: To count the items of all cells above the current cell, write %CALC{"$COUNTITEMS( $ABOVE() )"}%
>
>
"$COUNTITEMS(list)" Counts individual items in a list. Example: %CALC{"$COUNTITEMS( $ABOVE() )"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
 
"$COUNTSTR(list, str)" Counts the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list. Example: To count the number of non empty cells above the current cell, write %CALC{"$COUNTSTR( $ABOVE() )"}%; to count the number of cells equal to DONE, write %CALC{"$COUNTSTR( $ABOVE(), DONE )"}%;
Added:
>
>
"$COUNTUNIQUE(list)" Counts unique items in a list, separated by comma and/or space. Example: %CALC{"$COUNTUNIQUE( $ABOVE() )"}% returns Alice: 2, Mike: 1, Tom: 2 assuming the cells above the current cell contain Alice and Tom, Mike and Alice, Tom
 
"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
Line: 49 to 50
 
"$FORMATTIME( serial, text )" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME( 0, $year/$month/$day GMT )"}% returns 1970/01/01 GMT
"$FORMATGMTIME( serial, text )" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME( 1041379200, $day $mon $year )"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. 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. See also $SET(). Example: %CALC{"$GET( my_total )"}% returns the value of the my_total variable
Changed:
<
<
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less then), <= (less then or equal), == (equal), != (not equal), >= (greater then or equal), >= (greater then). Example: %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
>
>
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Example: %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
 
"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Line: 131 to 132
 

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 24 Oct 2003
>
>
Plugin Version: 27 Feb 2004
 
Change History:
<-- specify latest version first -->
 
Added:
>
>
27 Feb 2004: Added $COUNTUNIQUE()
 
24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
21 Oct 2003: Added support for lists (1, 2, 3) and lists of table ranges (R1:C1..R1:C5, R3:C1..R3:C5) for all functions that accept a table range; added $TIMEADD(); in $TIMEDIFF() added week unit; in $FORMATTIME() changed $weekday to $wd and added $wday and $weekday
14 Oct 2003: Added $TIME(), $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF()
Line: 151 to 153
 
16 Apr 2001: Fixed div by 0 bug in $AVERAGE
17 Mar 2001: Initial version
CPAN Dependencies: none
Added:
>
>
TWiki:Plugins/Benchmark: GoodStyle 99%, FormattedSearch 99%, SpreadSheetPlugin 95%
 
Other Dependencies: none
Perl Version: 5.000 and up
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin
Line: 158 to 161
  Related Topics: TWikiPreferences, TWikiPlugins
Changed:
<
<
-- TWiki:Main/PeterThoeny - 24 Oct 2003
>
>
-- TWiki:Main/PeterThoeny - 27 Feb 2004

Revision 12003-12-12 - PeterThoeny

Line: 1 to 1
Added:
>
>

TWiki Spreadsheet Plugin

This Plugin adds speadsheet capabilities to TWiki topics. Formulas like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables.

Example:

Region: Sales:
Northeast 320
Northwest 580
South 240
Europe 610
Asia 220
Total: 1970

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 formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COL(0)..R$ROW(-1):C$COL(0) )"}%
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. %CALC{"$SUM( 3, 5, 7 )"}%
  • A table cell can be addressed as R1:C1. Table address matrix:
    R1:C1 R1:C2 R1:C3 R1:C4
    R2:C1 R2:C2 R2:C3 R2:C4
  • A table cell range is defined by two cell addresses separated by "..", e.g. "row 1 through 20, column 3" is: R1:C3..R20:C3
  • 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

Function Description
"$ABOVE()" The address range of cells above the current cell
"$AVERAGE(list)" The average of the content of a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
"$CODE(text)" The ASCII numeric value of the first character in text. Example: %CALC{"$CODE(abc)"}% returns 97
"$COLUMN(offset)" The current column number with an optional offset
"$COUNTITEMS(list)" The count of individual items in a list. Example: To count the items of all cells above the current cell, write %CALC{"$COUNTITEMS( $ABOVE() )"}%
"$COUNTSTR(list, str)" Counts the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list. Example: To count the number of non empty cells above the current cell, write %CALC{"$COUNTSTR( $ABOVE() )"}%; to count the number of cells equal to DONE, write %CALC{"$COUNTSTR( $ABOVE(), DONE )"}%;
"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
"$FIND(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_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; an empty string is returned if nothing is matched. Examples:
%CALC{"$FIND(f, fluffy)"}% returns 1
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
%CALC{"$FIND(@, fluffy, 1)"}% returns an empty string
"$FORMAT(type, prec, number)" Formats a number to a certain type and precision. Types with examples:
  - %CALC{"$FORMAT( COMMA, 2, 12345.6789 )"}% returns 12,345.68
  - %CALC{"$FORMAT( DOLLAR, 2, 12345.67 )"}% returns $12,345.68
  - %CALC{"$FORMAT( NUMBER, 1, 12345.67 )"}% returns 12345.7
  - %CALC{"$FORMAT( PERCENT, 1, 0.1234567 )"}% returns 12.3%
"$FORMATTIME( serial, text )" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME( 0, $year/$month/$day GMT )"}% returns 1970/01/01 GMT
"$FORMATGMTIME( serial, text )" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME( 1041379200, $day $mon $year )"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. 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. See also $SET(). Example: %CALC{"$GET( my_total )"}% returns the value of the my_total variable
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less then), <= (less then or equal), == (equal), != (not equal), >= (greater then or equal), >= (greater then). Example: %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LOWER(text)" The lower case string of a text. Example: %CALC{"$LOWER( $T(R1:C5) )"}% returns the lower case string of the text in cell R1:C5
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN( 3, 9, 4, 5 )"}% returns 4.5
"$MIN(list)" The smallest value of a list or range of cells. Example: %CALC{"$MIN( 15, 3, 28 )"}% returns 3
"$MULT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$MULT($LEFT())"}%
"$NOP(text)" A no-operation. Allows one to defy the order of Plugin execution. For example, it will allow preprossing to be done before %SEARCH{}% is evaluated. Use $per to escape '%'.
"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
"$RIGHT()" The address range of cells to the right of the current cell
"$ROUND(formula)" Evaluates a simple formula and rounds the result up or down to the nearest integer. Example: %CALC{"$INT( 10 / 6 )"}% returns 2
"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns an empty string
"$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. See also $GET(). 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
"$SUBSTITUTE(text, old, new, instance, option)" Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r. See also $REPLACE(), $TRANSLATE(). Examples:
%CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
"$SUM(list)" The sum of a list or range of cells. Example: To sum up column 5 excluding the title row, write: %CALC{"$SUM( R2:C5..R$ROW(-1):C5 )"}% in the last row; or simply %CALC{"$SUM( $ABOVE() )"}%
"$SUMDAYS(list)" The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours. Example: %CALC{"$SUMDAYS( 2w, 1, 2d, 4h )"}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
"$SUMPRODUCT(list, list, ...)" The scalar product on ranges of cells. Example: %CALC{"$SUM( R2:C1..R4:C1, R2:C5..R4:C5 )"}% evaluates and returns ($T(R2:C1) * $T(R2:C5) + $T(R3:C1) * $T(R3:C5) + $T(R4:C1) * $T(R4:C5))
"$T(address)" The content of a cell. Example: %CALC{"$T(R1:C5)"}% returns the text in cell R1:C5
"$TRANSLATE(text, from, to)" Translate text from a set of characters to another set, one character by one. The text may contain commas; the last two comma separated parameters are required. For from and to parameters, you can write $comma to escape comma, $sp to escape space. See also $REPLACE(), $SUBSTITUTE(). Examples:
%CALC{"$TRANSLATE(boom,bm,cl)"}% returns cool
%CALC{"$TRANSLATE(one, two,$comma,;)"}% returns one; two
"$TIME(text)" Converts a date string into a serialized date number (seconds since the Epoch, e.g. midnight, 01 Jan 1970). Current time is taken if the date string is empty. Supported date formats: 31 Dec 2009; 31 Dec 2009 GMT; 31 Dec 09; 31-Dec-2009; 31/Dec/2009; 2009/12/31; 2009-12-31; 2009/12/31; 2009/12/31 23:59; 2009/12/31 - 23:59; 2009-12-31-23-59; 2009/12/31 - 23:59:59; 2009.12.31.23.59.59. Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TIME( 2003/10/14 GMT )"}% returns 1066089600
"$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. See also $TIME(), $TIMEDIFF(), $TODAY(), $FORMATTIME(). Example: %CALC{"$TIMEADD( $TIME(), 2, week )"}% returns the serialized date two weeks from now
"$TIMEDIFF( serial_1, serial_2, unit )" Time difference between two serialized dates. The unit is seconds if not specified; unit can be specified as in $TIMEADD(). Note: An approximation is used for month and year calculations. Use $FORMAT() or $INT() to format real numbers. See also $TIME(), $TIMEADD(), $TODAY(), $FORMATTIME(). Example: %CALC{"$TIMEDIFF( $TIME(), $EVAL($TIME()+90), minute )"}% returns 1.5
"$TODAY()" Get the serialized date of today at midnight GMT. The related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT. See also $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
"$TRIM(text)" Removes all spaces from text except for single spaces between words. Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces.
"$UPPER(text)" The upper case string of a text. Example: %CALC{"$UPPER( $T(R1:C5) )"}% returns the upper case string of the text in cell R1:C5

Bug Tracking Example

Bug#: Priority: Subject: Status: Days to fix
Bug:1231 Low File Open ... Open 3
Bug:1232 High Memory Window ... Fixed 2
Bug:1233 Medium Usability issue ... Assigned 5
Bug:1234 High No arrange ... Fixed 1
Total: 4 High: 2
Low: 1
Medium: 1
. Assigned: 1
Fixed: 2
Open: 1
Total: 11

The last row is defined as:

| Total: %CALC{"$ROW(-2)"}% \ 
  | %CALC{"$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}% | . \ 
  | %CALC{"$COUNTITEMS( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}% \ 
  |  Total: %CALC{"$SUM( R2:C$COLUMN()..R$ROW(-1):C$COLUMN() )"}% |

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.

SpreadSheetPlugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%

  • One line description, is shown in the TextFormattingRules topic:
    • Set SHORTDESCRIPTION = Add spreadsheet calculation like "$SUM( $ABOVE() )" to tables located in TWiki topics.

  • Debug plugin: (See output in data/debug.txt)
    • Set DEBUG = 0

  • Do not handle %CALC{}% tag in included topic while including topic: (default: 1)
    • Set SKIPINCLUDE = 1

Plugin Installation Instructions

Note: You do not need to install anything on the browser to use this plugin. Below installation instructions are for the administrator who needs to install this plugin on the TWiki server.

  • Download the ZIP file from the SpreadSheetPlugin home
  • Unzip SpreadSheetPlugin.zip in your twiki installation directory. Content:
    File: Description:
    data/TWiki/SpreadSheetPlugin.txt Plugin topic
    data/TWiki/SpreadSheetPlugin.txt,v Plugin topic repository
    lib/TWiki/Plugins/SpreadSheetPlugin.pm Plugin Perl module
  • Test if the "Total" in the first table in this topic is correct.

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Plugin Version: 24 Oct 2003
Change History:
<-- specify latest version first -->
 
24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
21 Oct 2003: Added support for lists (1, 2, 3) and lists of table ranges (R1:C1..R1:C5, R3:C1..R3:C5) for all functions that accept a table range; added $TIMEADD(); in $TIMEDIFF() added week unit; in $FORMATTIME() changed $weekday to $wd and added $wday and $weekday
14 Oct 2003: Added $TIME(), $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF()
13 Oct 2003: Added $MULT(), contributed by TWiki:Main/GerritJanBaarda
30 Jul 2003: Added $TRANSLATE()
19 Jul 2003: Added $FIND(), $NOP(), $REPLACE(), $SEARCH(), $SUBSTITUTE(), contributed by TWiki:Main/PaulineCheung
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
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
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.000 and up
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev

Related Topics: TWikiPreferences, TWikiPlugins

-- TWiki:Main/PeterThoeny - 24 Oct 2003

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.SpreadSheetPlugin.