%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:
| Interactive example: | |||||||||||||||
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.) |
%CALC{"..."}%
variable, which gets rendered according to the built-in function(s) found between the quotes.
$FUNCNAME(parameter)
%CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
%CALC{"$SUM( 3, 5, 7 )"}%
R1:C1
. Table address matrix: R1:C1 | R1:C2 | R1:C3 | R1:C4 |
R2:C1 | R2:C2 | R2:C3 | R2:C4 |
".."
, e.g. "row 1 through 20, column 3" is: R1:C3..R20:C3
%CALC{"$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )"}%
%CALC{"Total: $SUM($ABOVE()) kg"}%
( bold )
( bold italic )
$ABOVE( )
%CALC{"$SUM($ABOVE())"}%
returns the sum of cells above the current cell
$LEFT()
, $RIGHT()
$AND( list )
%CALC{"$AND(1, 0, 1)"}%
returns 0
$NOT()
, $IF()
, $OR()
, $WHILE()
, $XOR()
$AVERAGE( list )
%CALC{"$AVERAGE(R2:C5..R$ROW(-1):C5)"}%
returns the average of column 5, excluding the title row
$LIST()
, $MAX()
, $MEDIAN()
, $MIN()
text
is flipped, useful to obfuscate text. Bit-XORing text twice will restore the original text.
$BITXOR( text )
%CALC{"$BITXOR(A123)"}%
returns ŸÎÍÌ
%CALC{"$BITXOR($BITXOR(anything))"}%
returns anything
$HEXDECODE()
, $HEXENCODE()
, $LEFTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SUBSTITUTE()
, $TRANSLATE()
, $XOR()
$INT()
to truncate a number towards zero; use $FLOOR()
to get the largest previous integer
$CEILING( num )
%CALC{"$CEILING(5.4)"}%
returns 6
%CALC{"$CEILING(-5.4)"}%
returns -5
$EVAL()
, $FLOOR()
, $INT()
, $ROUND()
, $VALUE()
$CHAR( number )
%CALC{"$CHAR(97)"}%
returns a
$CODE()
$CODE( text )
%CALC{"$CODE(abc)"}%
returns 97
$CHAR()
$COLUMN( offset )
%CALC{"$COLUMN()"}%
returns 2
for the second column
$ROW()
, $T()
$COUNTITEMS( list )
%CALC{"$COUNTITEMS($ABOVE())"}%
returns Closed: 1, Open: 2
assuming one cell above the current cell contains Closed
and two cells contain Open
$COUNTSTR()
, $LIST()
, $WHILE()
$COUNTSTR( list, str )
%CALC{"$COUNTSTR($ABOVE())"}%
counts the number of non empty cells above the current cell
%CALC{"$COUNTSTR($ABOVE(), DONE)"}%
counts the number of cells equal to DONE
$COUNTITEMS()
, $LIST()
, $WHILE()
$DEF( list )
%CALC{"$DEF(R1:C1..R1:C3)"}%
$COUNTSTR()
, $LISTIF()
, $LIST()
1
if text
is empty, or 0
if not
$EMPTY( text )
%CALC{"$EMPTY(foo)"}%
returns 0
%CALC{"$EMPTY()"}%
returns 1
%CALC{"$EMPTY($TRIM( ))"}%
returns 1
$EXACT()
, $IF()
, $TRIM()
, $WHILE()
1234
), binary integers (0b1110011
), octal integers (01234
), hexadecimal integers (0x1234
) or of exponential notation (12.34e-56
)
$EVAL( formula )
%CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}%
returns 8.6
$CEILING()
, $EXEC()
, $FLOOR()
, $INT()
, $MOD()
, $ROUND()
, $VALUE()
1
if they are exactly the same, or 0
if not
$EXACT( text1, text2 )
%CALC{"$EXACT(foo, Foo)"}%
returns 0
%CALC{"$EXACT(foo, $LOWER(Foo))"}%
returns 1
$EMPTY()
, $IF()
, $TRIM()
$EXEC( formula )
%CALC{"$SET(msg, $NOEXEC(Hi $GET(name)))"}%
sets the msg
variable with raw formula Hi $GET(name)
%CALC{"$SET(name, Tom) $EXEC($GET(msg))"}%
executes content of msg
variable and returns Hi Tom
%CALC{"$SET(name, Jerry) $EXEC($GET(msg))"}%
returns Hi Jerry
$EVAL()
, $GET()
, $NOEXEC()
, $SET()
TopicName
or a Web.TopicName
. Current web is used if web is not specified.
$EXISTS( topic )
%CALC{"$EXISTS(WebHome)"}%
returns 1
%CALC{"$EXISTS(ThisDoesNotExist)"}%
returns 0
$EXACT()
, $IF()
, $TRIM()
$EXP( num )
%CALC{"$EXP(1)"}%
returns 2.71828182845905
$LN()
, $LOG()
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.
$FIND( string, text, start )
%CALC{"$FIND(f, fluffy)"}%
returns 1
%CALC{"$FIND(f, fluffy, 2)"}%
returns 4
%CALC{"$FIND(@, fluffy, 1)"}%
returns 0
$INSERTSTRING()
, $LEFTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SUBSTRING()
, $SEARCH()
$INT()
to truncate a number towards zero; use $CEILING()
to get the smallest following integer
$FLOOR( num )
%CALC{"$FLOOR(5.4)"}%
returns 5
%CALC{"$FLOOR(-5.4)"}%
returns -6
$CEILING()
, $EVAL()
, $INT()
, $ROUND()
, $VALUE()
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%
precision
indicates the the number of digits after the dot
$FORMAT( type, prec, number )
%CALC{"$FORMAT(COMMA, 2, 12345.6789)"}%
returns 12,345.68
%CALC{"$FORMAT(DOLLAR, 2, 12345.67)"}%
returns $12,345.68
%CALC{"$FORMAT(KB, 2, 1234567)"}%
returns 1205.63 KB
%CALC{"$FORMAT(MB, 2, 1234567)"}%
returns 1.18 MB
%CALC{"$FORMAT(KBMB, 2, 1234567)"}%
returns 1.18 MB
%CALC{"$FORMAT(KBMB, 2, 1234567890)"}%
returns 1.15 GB
%CALC{"$FORMAT(NUMBER, 1, 12345.67)"}%
returns 12345.7
%CALC{"$FORMAT(PERCENT, 1, 0.1234567)"}%
returns 12.3%
$FORMATTIME()
, $FORMATTIMEDIFF()
, $ROUND()
$FORMATTIME()
.
$FORMATGMTIME( serial, text )
%CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}%
returns 01 Jan 2003
$FORMATTIME()
, $FORMATTIMEDIFF()
, $TIME()
, $TIMEADD()
, $TIMEDIFF()
, $TODAY()
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
$isoweek
- ISO 8601 week number, one or two digits, 1..53
$isoweek(format)
- formatted ISO 8601 week number. These variables are expanded in format
: $isoweek($year)
- year of ISO 8601 week number, such as 2009
for 2010-01-03
$isoweek($wk)
- 2 digit ISO 8601 week number, such as 53
for 2010-01-03
$isoweek($day)
- day of ISO 8601 week number, starting with 1 for Monday, such as 7
for 2010-01-03
$isoweek($iso)
- full year-week ISO week number, such as 2009-W53
for 2010-01-03
$isoweek($yearW$wk$day)
- full year-week-day ISO week number, such as 2009W537
for 2010-01-03
$isoweek($year-W$wk-$day)
- full year-week-day ISO week number, such as 2009-W53-7
for 2010-01-03
$isoweek($year-W$wk)
- year-week ISO 8601 week number, such as 2009-W53
for 2010-01-03
GMT
to text
to indicate Greenwich time zone, or use $FORMATGMTIME()
.
$FORMATTIME( serial, text )
%CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}%
returns 1970/01/01 GMT
$FORMATGMTIME()
, $TIME()
, $FORMATTIMEDIFF()
, $TIMEADD()
, $TIMEDIFF()
, $TODAY()
time
to a human readable format, such as: 12 hours and 3 minutes
unit
can be second
, minute
, hour
, day
, month
, year
. Note: An approximation is used for month and year calculations.
precision
indicates the number of output units to use
$FORMATTIMEDIFF( unit, precision, time )
%CALC{"$FORMATTIMEDIFF(min, 1, 200)"}%
returns 3 hours
%CALC{"$FORMATTIMEDIFF(min, 2, 200)"}%
returns 3 hours and 20 minutes
%CALC{"$FORMATTIMEDIFF(min, 1, 1640)"}%
returns 1 day
%CALC{"$FORMATTIMEDIFF(min, 2, 1640)"}%
returns 1 day and 3 hours
%CALC{"$FORMATTIMEDIFF(min, 3, 1640)"}%
returns 1 day, 3 hours and 20 minutes
$FORMATTIME()
, $TIME()
, $TIMEADD()
, $TIMEDIFF()
$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.
$GET( name )
%CALC{"$GET(my_total)"}%
returns the value of the my_total
variable
$EXEC()
, $NOEXEC()
, $SET()
, $SETIFEMPTY()
, $SETM()
, $WHILE()
, TWiki:Plugins.SetGetPlugin
$HEXDECODE( hexcode )
%CALC{"$HEXDECODE(687474703A2F2F7477696B692E6F72672F)"}%
returns http://twiki.org/
$BITXOR()
, $HEXENCODE()
, $SUBSTITUTE()
, $TRANSLATE()
text
is encoded into two hexadecimal numbers.
$HEXENCODE( text )
%CALC{"$HEXENCODE(http://twiki.org/)"}%
returns 687474703A2F2F7477696B692E6F72672F
$BITXOR()
, $HEXDECODE()
, $SUBSTITUTE()
, $TRANSLATE()
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).
$IF( condition, value if true, value if 0 )
%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
$AND()
, $EMPTY()
, $EXACT()
, $LISTIF()
, $NOT()
, $OR()
, $WHILE()
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
$INSERTSTRING( text, start, new )
%CALC{"$INSERTSTRING(abcdefg, 2, XYZ)"}%
returns abXYZcdefg
%CALC{"$INSERTSTRING(abcdefg, -2, XYZ)"}%
returns abcdeXYZfg
$FIND()
, $LEFTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SEARCH()
, $SUBSTITUTE()
, $SUBSTRING()
, $TRANSLATE()
1234
), binary integers (0b1110011
), octal integers (01234
), hexadecimal integers (0x1234
) or of exponential notation (12.34e-56
)
$INT( $VALUE( number ) )
$INT( formula )
%CALC{"$INT(10 / 4)"}%
returns 2
%CALC{"$INT($VALUE(09))"}%
returns 9
$CEILING()
, $EVAL()
, $FLOOR()
, $ROUND()
, $VALUE()
$LEFT( )
%CALC{"$SUM($LEFT())"}%
returns the sum of cells to the left of the current cell
$ABOVE()
, $RIGHT()
num
of characters from the left end of text
; the leftmost character is returned if num
is missing
$LEFTSTRING( text, num )
%CALC{"$LEFTSTRING(abcdefg)"}%
returns a
%CALC{"$LEFTSTRING(abcdefg, 5)"}%
returns abcde
$BITXOR()
, $FIND()
, $INSERTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SEARCH()
, $SUBSTITUTE()
, $SUBSTRING()
, $TRANSLATE()
$LENGTH( text )
%CALC{"$LENGTH(abcd)"}%
returns 4
$LISTSIZE()
$LIST( range )
%CALC{"$LIST($LEFT())"}%
returns Apples, Lemons, Oranges, Kiwis
assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
$AVERAGE()
, $COUNTITEMS()
, $COUNTSTR()
, $DEF()
, $LISTIF()
, $LISTITEM()
, $LISTJOIN()
, $LISTMAP()
, $LISTNONEMPTY()
, $LISTRAND()
, $LISTREVERSE()
, $LISTSHUFFLE()
, $LISTSIZE()
, $LISTSORT()
, $LISTTRUNCATE()
, $LISTUNIQUE()
, $MAX()
, $MEDIAN()
, $MIN()
, $PRODUCT()
, $SPLIT()
, $SUM()
, $SUMDAYS()
, $SUMPRODUCT()
$IF()
, you can use $item
to indicate the current element, and $index
for the list index, starting at 1
$LISTIF( condition, list )
%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
$EMPTY()
, $EXACT()
, $IF()
, $LIST()
, $LISTITEM()
, $LISTMAP()
, $LISTNONEMPTY()
, $LISTREVERSE()
, $LISTSIZE()
, $LISTSORT()
, $LISTUNIQUE()
, $SUM()
, $WHILE()
$LISTITEM( index, list )
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}%
returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}%
returns Kiwi
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTMAP()
, $LISTNONEMPTY()
, $LISTRAND()
, $LISTREVERSE()
, $LISTSIZE()
, $LISTSORT()
, $LISTUNIQUE()
, $SPLIT()
, $SUM()
separator
string, which may include $comma
for comma, $n
for newline, $sp
for space, and $empty
to join a list without a separator.
$LISTJOIN( separator, list )
%CALC{"$LISTJOIN($n, Apple, Orange, Apple, Kiwi)"}%
returns the four items separated by new lines
%CALC{"$LISTJOIN($empty, Apple, Orange, Apple, Kiwi)"}%
returns AppleOrangeAppleKiwi
$LIST()
, $LISTNONEMPTY()
, $LISTSIZE()
, $SPLIT()
$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.
$LISTMAP( formula, list )
%CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}%
returns 1: 6, 2: 10, 3: 14, 4: 22
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTNONEMPTY()
, $LISTREVERSE()
, $LISTSIZE()
, $LISTSORT()
, $LISTUNIQUE()
, $SPLIT()
, $SUM()
, $WHILE()
$LISTNONEMPTY( list )
%CALC{"$LISTNONEMPTY(, Apple, Orange, , Kiwi)"}%
returns Apple, Orange, Kiwi
$LISTIF()
, $LISTITEM()
, $LISTMAP()
, $LISTSIZE()
, $LISTUNIQUE()
$LISTRAND( list )
%CALC{"$LISTRAND(Apple, Orange, Apple, Kiwi)"}%
returns one of the four elements
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTMAP()
, $LISTSHUFFLE()
, $LISTSIZE()
, $LISTSORT()
, $LISTUNIQUE()
, $RAND()
, $SUM()
$LISTREVERSE( list )
%CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}%
returns Kiwi, Apple, Orange, Apple
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTMAP()
, $LISTSIZE()
, $LISTSORT()
, $LISTUNIQUE()
, $SUM()
$LISTSIZE( list )
%CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}%
returns 4
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTJOIN()
, $LISTMAP()
, $LISTREVERSE()
, $LISTSORT()
, $LISTTRUNCATE()
, $LISTUNIQUE()
, $SPLIT()
, $SUM()
$LISTSHUFFLE( list )
%CALC{"$LISTSHUFFLE(Apple, Orange, Apple, Kiwi)"}%
returns the four elements in random order
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTMAP()
, $LISTRAND()
, $LISTSIZE()
, $LISTSORT()
, $LISTUNIQUE()
, $RAND()
, $SUM()
$LISTSORT( list )
%CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}%
returns Apple, Apple, Kiwi, Orange
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTMAP()
, $LISTREVERSE()
, $LISTSHUFFLE()
, $LISTSIZE()
, $LISTUNIQUE()
, $SUM()
$LISTTRUNCATE( size, list )
%CALC{"$LISTTRUNCATE(2, Apple, Orange, Kiwi)"}%
returns Apple, Orange
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTMAP()
, $LISTSIZE()
, $LISTSORT()
, $LISTUNIQUE()
, $SUM()
$LISTUNIQUE( list )
%CALC{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"}%
returns Apple, Orange, Kiwi
$COUNTITEMS()
, $COUNTSTR()
, $LIST()
, $LISTIF()
, $LISTITEM()
, $LISTMAP()
, $LISTNONEMPTY()
, $LISTREVERSE()
, $LISTSIZE()
, $LISTSORT()
, $SUM()
$LN( num )
%CALC{"$LN(10)"}%
returns 2.30258509299405
$EXP()
, $LOG()
$LOG( num, base )
%CALC{"$LOG(1000)"}%
returns 3
%CALC{"$LOG(16, 2)"}%
returns 4
$EXP()
, $LN()
$LOWER(text)
%CALC{"$LOWER( $T(R1:C5) )"}%
returns the lower case string of the text in cell R1:C5
$PROPER()
, $PROPERSPACE()
, $TRIM()
, $UPPER()
$MAX( list )
%CALC{"$MAX($LEFT())"}%
$LIST()
, $MEDIAN()
, $MIN()
, $PERCENTILE()
$MEDIAN( list )
%CALC{"$MEDIAN(3, 9, 4, 5)"}%
returns 4.5
$LIST()
, $MAX()
, $MIN()
, $PERCENTILE()
$MIN( list )
%CALC{"$MIN(15, 3, 28)"}%
returns 3
$LIST()
, $MAX()
, $MEDIAN()
, $PERCENTILE()
num
by divisor
$MOD( num, divisor )
%CALC{"$MOD(7, 3)"}%
returns 1
$EVAL()
$EXEC()
.
$NOEXEC( formula )
%CALC{"$SET(msg, $NOEXEC(Hi $GET(name)))"}%
sets the msg
variable with the formula Hi $GET(name)
without executing it
$EVAL()
, $EXEC()
, $GET()
, $SET()
%SEARCH{}%
is evaluated. The percent character '%' can be escaped with $percnt
. The quote character '"' can be escaped with $quot
.
$NOP( text )
num
is not zero, 1 if zero
$NOT( num )
%CALC{"$NOT(0)"}%
returns 1
$AND()
, $EMPTY()
, $IF()
, $OR()
, $WHILE()
, $XOR()
$OR( list )
%CALC{"$OR(1, 0, 1)"}%
returns 1
$AND()
, $IF()
, $NOT()
, $WHILE()
, $XOR()
$PERCENTILE( num, list )
%CALC{"$PERCENTILE(75, 400, 200, 500, 100, 300)"}%
returns 450
$LIST()
, $MAX()
, $MEDIAN()
, $MIN()
$PI( )
%CALC{"$PI()"}%
returns 3.14159265358979
$PRODUCT( list )
%CALC{"$PRODUCT($LEFT())"}%
$LIST()
, $PRODUCT()
, $SUM()
, $SUMPRODUCT()
$PROPER( text )
%CALC{"$PROPER(a small STEP)"}%
returns A Small Step
%CALC{"$PROPER(f1 (formula-1))"}%
returns F1 (Formula-1)
$LOWER()
, $PROPERSPACE()
, $TRIM()
, $UPPER()
][
. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE plugins setting are excluded
$PROPERSPACE( text )
%CALC{"$PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh)"}%
returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh
$LOWER()
, $PROPER()
, $TRIM()
, $UPPER()
max
, or 0 and 1 if max is not specified
$RAND( max )
$EVAL()
, $LISTRAND()
, $LISTSHUFFLE()
$REPEAT( text, num )
%CALC{"$REPEAT(/\, 5)"}%
returns /\/\/\/\/\
$WHILE()
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
$REPLACE( text, start, num, new )
%CALC{"$REPLACE(abcdefghijk, 6, 5, *)"}%
returns abcde*k
$BITXOR()
, $FIND()
, $INSERTSTRING()
, $LEFTSTRING()
, $RIGHTSTRING()
, $SEARCH()
, $SUBSTITUTE()
, $SUBSTRING()
, $TRANSLATE()
$RIGHT( )
%CALC{"$SUM($RIGHT())"}%
returns the sum of cells to the right of the current cell
$ABOVE()
, $LEFT()
num
of characters from the right end of text
; the rightmost character is returned if num
is missing
$RIGHTSTRING( text, num )
%CALC{"$RIGHTSTRING(abcdefg)"}%
returns g
%CALC{"$RIGHTSTRING(abcdefg, 5)"}%
returns cdefg
$BITXOR()
, $FIND()
, $INSERTSTRING()
, $LEFTSTRING()
, $REPLACE()
, $SEARCH()
, $SUBSTITUTE()
, $SUBSTRING()
, $TRANSLATE()
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
$ROUND( formula, digits )
%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
$CEILING()
, $EVAL()
, $FLOOR()
, $INT()
, $FORMAT()
$ROW( offset )
%CALC{"$ROW(-2)"}%
$COLUMN()
, $T()
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
$SEARCH( string, text, start )
%CALC{"$SEARCH([uy], fluffy)"}%
returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}%
returns 6
%CALC{"$SEARCH([abc], fluffy,)"}%
returns 0
$FIND()
, $INSERTSTRING()
, $LEFTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SUBSTRING()
$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
$SET( name, value )
%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
$EXEC()
, $GET()
, $NOEXEC()
, $SETIFEMPTY()
, SETM()
, $WHILE()
, TWiki:Plugins.SetGetPlugin
$SETIFEMPTY( name, value )
%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
$GET()
, $SET()
+
(add), -
(subtract), *
(multiply), or /
(divide) something to the variable. This function returns no output. Use $GET()
to retrieve variables
$SETM( name, formula )
%CALC{"$SETM(total, + $SUM($LEFT()))"}%
adds the sum of all table cells on the left to the total
variable, and returns an empty string
$GET()
, $SET()
, $SETIFEMPTY()
, $WHILE()
num
is negative, 0 if zero, or 1 if positive
$SIGN( num )
%CALC{"$SIGN(-12.5)"}%
returns -1
$ABS()
, $EVAL()
, $EVEN()
, $INT()
, $NOT()
, $ODD()
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*
).
$SPLIT( separator, text )
%CALC{"$SPLIT(, Apple Orange Kiwi)"}%
returns Apple, Orange, Kiwi
%CALC{"$SPLIT(-, Apple-Orange-Kiwi)"}%
returns Apple, Orange, Kiwi
%CALC{"$SPLIT([-:]$sp*, Apple-Orange: Kiwi)"}%
returns Apple, Orange, Kiwi
(the separator means: Dash or colon, followed by optional spaces
%CALC{"$SPLIT($empty, Apple)"}%
returns A, p, p, l, e
$LIST()
, $LISTJOIN()
, $LISTSIZE()
$SQRT( num )
%CALC{"$SQRT(16)"}%
returns 4
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
$SUBSTITUTE( text, old, new, instance, option )
%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
$BITXOR()
, $HEXDECODE()
, $HEXENCODE()
, $INSERTSTRING()
, $LEFTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SUBSTRING()
, $TRANSLATE()
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
$SUBSTRING( text, start, num )
%CALC{"$SUBSTRING(abcdefghijk, 3, 5)"}%
returns cdefg
$FIND()
, $INSERTSTRING()
, $LEFTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SEARCH()
, $SUBSTITUTE()
, $TRANSLATE()
$SUM( list )
%CALC{"$SUM(R2:C5..R$ROW(-1):C5)"}%
in the last row; or simply %CALC{"$SUM($ABOVE())"}%
$LIST()
, $PRODUCT()
, $SUMPRODUCT()
, $WORKINGDAYS()
h
, hours
, d
, days
, w
, weeks
suffix. One week is assumed to have 5 working days, one day 8 hours
$SUMDAYS( list )
%CALC{"$SUMDAYS(2w, 1, 2d, 4h)"}%
returns 13.5
, the evaluation of (2*5 + 1 + 2 + 4/8)
$SUM()
, $TIME()
, $FORMATTIME()
$SUMPRODUCT( list, list, list... )
%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))
$LIST()
, $PRODUCT()
, $SUM()
$T( address )
%CALC{"$T(R1:C5)"}%
returns the text in cell R1:C5
$COLUMN()
, $ROW()
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 add token $comma
for comma, $sp
for space, and $n
for newline
$TRANSLATE( text, from, to )
%CALC{"$TRANSLATE(boom,bm,cl)"}%
returns cool
%CALC{"$TRANSLATE(one, two,$comma,;)"}%
returns one; two
$BITXOR()
, $HEXDECODE()
, $HEXENCODE()
, $INSERTSTRING()
, $LEFTSTRING()
, $REPLACE()
, $RIGHTSTRING()
, $SUBSTRING()
, $SUBSTITUTE()
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
$TIME( text )
%CALC{"$TIME(2003/10/14 GMT)"}%
returns 1066089600
$FORMATGMTIME()
, $FORMATTIME()
, $FORMATTIMEDIFF()
, $TIMEADD()
, $TIMEDIFF()
, $TODAY()
, $WORKINGDAYS()
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
$TIMEADD( serial, value, unit )
%CALC{"$TIMEADD($TIME(), 2, week)"}%
returns the serialized date two weeks from now
$FORMATTIME()
, $FORMATGMTIME()
, $TIME()
, $TIMEDIFF()
, $TODAY()
unit
is seconds if not specified; unit can be specified as in $TIMEADD()
.
$ROUND()
to round day
unit to account for daylight savings time change. Use $FORMAT()
, $FORMATTIMEDIFF()
or $INT()
to format real numbers
$TIMEDIFF( serial_1, serial_2, unit )
%CALC{"$TIMEDIFF($TIME(), $EVAL($TIME()+90), minute)"}%
returns 1.5
%CALC{"$ROUND($TIMEDIFF($TIME(2009/03/06),$TIME(2009/03/13), day))"}%
returns 7
(or 6.95833333333333
without the $ROUND()
)
$FORMAT()
, $FORMATGMTIME()
, $FORMATTIME()
, $FORMATTIMEDIFF()
, $INT()
, $TIME()
, $TIMEADD()
, $TODAY()
, $WORKINGDAYS()
$TIME()
returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT
$TODAY( )
%CALC{"$TODAY()"}%
returns the number of seconds since Epoch
$FORMATTIME()
, $FORMATGMTIME()
, $TIME()
, $TIMEADD()
, $TIMEDIFF()
$TRIM( text )
%CALC{"$TRIM( eat spaces )"}%
returns eat spaces
$EMPTY()
, $EXACT()
, $PROPERSPACE()
$UPPER( text )
%CALC{"$UPPER($T(R1:C5))"}%
returns the upper case string of the text in cell R1:C5
$LOWER()
, $PROPER()
, $PROPERSPACE()
, $TRIM()
text
. Returns 0
if not found
$VALUE( text )
%CALC{"$VALUE(US$1,200)"}%
returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}%
returns 1234
%CALC{"$VALUE(Total: -12.5)"}%
returns -12.5
$CEILING()
, $EVAL()
, $FLOOR()
, $INT()
, $ROUND()
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).
condition
and do
are evaluated in each cycle; a $counter
starting at 1 can be used in condition
and do
.
$WHILE( condition, do something )
%CALC{"$WHILE($counter<=10, $counter )"}%
returns 1 2 3 4 5 6 7 8 9 10
%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,
$AND()
, $EMPTY()
, $EXACT()
, $GET()
, $IF()
, $LISTIF()
, $NOT()
, $OR()
, $SET()
, $SETM()
, $REPEAT()
$WORKINGDAYS( serial_1, serial_2 )
%CALC{"$WORKINGDAYS($TIME(2004/07/15), $TIME(2004/08/03))"}%
returns 13
$SUMDAYS()
, $TIME()
, $TIMEDIFF()
$XOR( list )
%CALC{"$XOR(0, 0)"}%
returns 0
%CALC{"$XOR(0, 1)"}%
returns 1
%CALC{"$XOR(1, 0)"}%
returns 1
%CALC{"$XOR(1, 1)"}%
returns 0
%CALC{"$XOR(1, 0, 1)"}%
returns 0
$AND()
, $BITXOR()
, $IF()
, $NOT()
, $OR()
, $WHILE()
%
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:
%SEARCH{ .... format="| $topic | $percntCALC{$IF($EXACT($formfield(Tested), Yes), %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-yes.gif, %PUBURL%/%SYSTEMWEB%/TWikiDocGraphics/choice-no.gif)}$percnt |" }%
<!-- * Set MYFORMULA = $EVAL($SUBSTITUTE(...etc...)) --> | A | 1 | %CALC{%MYFORMULA%}% | | B | 2 | %CALC{%MYFORMULA%}% | | C | 3 | %CALC{%MYFORMULA%}% |
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 |
| 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. 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>_<setting>%
, i.e. %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
"$SUM( $ABOVE() )"
to TWiki tables or anywhere in topic text
data/debug.txt
) %CALC{}%
variable in included topic while including topic: (default: 1) (See note CALC in Included Topics) $PROPERSPACE(text)
function. This comma delimited list can be overloaded by a DONTSPACE preferences variable: 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 |
configure
in your TWiki installation, and enable the plugin in the {Plugins} section.
Plugin Author: | TWiki:Main.PeterThoeny |
Copyright: | © 2001-2012 Peter Thoeny, Twiki, Inc. © 2008-2012 TWiki:TWiki.TWikiContributor |
License: | GPL (GNU General Public License) |
Plugin Version: | 2012-01-13 |
Change History: | |
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" |
2011-04-25: | TWikibug:Item6690: Added $BITXOR(), $HEXDECODE(), $HEXENCODE(), $XOR() |
2011-04-08: | TWikibug:Item6681: Added $WHILE() |
2011-04-06: | TWikibug:Item6679: Fixed small issue with $LISTRAND(), where last item only got 50% of fair share to get picked |
2011-03-25: | TWikibug:Item6669: Added $LISTNONEMPTY() |
2011-03-24: | TWikibug:Item6668: Fixed $LIST() not flattening a list in a cell TWikibug:Item6667: Fixed $RIGHT() having wrong result due to incorrect start cell |
2011-03-22: | TWikibug:Item6666: Added $SPLIT(); renamed $nop separator token of $LISTJOIN() to $empty (keeping $nop as undocumented feature) |
2010-08-27: | TWikibug:Item6526: Added ISO 8601 week number to $FORMATTIME(), contributed by TWiki:Main.PeterPayne |
2010-08-04: | TWikibug:Item6537: Fixed for $EVAL(2+08) returning "illegal octal digit" error instead of 10 |
2010-07-17: | TWikibug:Item6525: Added $n token to TRANSLATE for newline |
2010-05-27: | TWikibug:Item6506: Document delayed evaluation of CALC in included topics |
2010-05-26: | TWikibug:Item6504: Added empty ($nop) separator to $LISTJOIN() |
2010-06-25: | TWikibug:Item6493: Fixed $PRODUCT(0,4) returning 4 instead of 0 TWikibug:Item5163: Fix for plugin causing table to misrender an empty "||" row |
2010-05-22: | TWikibug:Item6472: Added 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() |
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 |
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() |
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 |
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 |
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() |
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 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 |
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 |