Difference: SpreadSheetPlugin (24 vs. 25)

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
<--                                                                                                                            -->
123 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 246 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
 
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.