# Difference: SpreadSheetPlugin (10 vs. 11)

#### Revision 1127 Jun 2005 - PeterThoeny

Line: 1 to 1

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:
<
<
• Related: `\$SIGN()`
>
>
• Related: `\$SIGN()`, `\$EVEN()`, `\$ODD()`

### AND( list ) -- logcial AND of a list

Line: 119 to 119

• Related: `\$COUNTSTR()`, `\$LISTIF()`, `\$LIST()`

Changed:
<
<

>
>

### 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:
<
<
• Related: `\$INT()`, `\$MOD()`, `\$ROUND()`, `\$VALUE()`
>
>
• Related: `\$EXEC()`, `\$INT()`, `\$MOD()`, `\$ROUND()`, `\$VALUE()`

### EVEN( num ) -- test for even number

• Syntax: `\$EVEN( num )`
• Example: `%CALC{"\$EVEN(2)"}%` returns `1`
• Related: `\$ABS()`, `\$MOD()`, `\$ODD()`, `\$SIGN()`

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

Line: 133 to 139

• Example: `%CALC{"\$EXACT(foo, \$LOWER(Foo))"}%` returns `1`
• Related: `\$IF()`, `\$TRIM()`
>
>

### EXEC( formula ) -- execute a spreadsheet formula

• Execute a spreadsheet formula, typically retrieved from a variable. This can be used to store a formula in a variable once and execute it many times using different parameters.
• Syntax: `\$EXEC( formula )`
• Example: `%CALC{"\$SET(msg, \$NOEXEC(Hi \$GET(name)))"}%` sets the `msg` variable with raw formula `Hi \$GET(name)`
• Example: `%CALC{"\$SET(name, Tom) \$EXEC(\$GET(msg))"}%` executes content of `msg` variable and returns `Hi Tom`
• Example: `%CALC{"\$SET(name, Jerry) \$EXEC(\$GET(msg))"}%` returns `Hi Jerry`
• Related: `\$EVAL()`, `\$GET()`, `\$NOEXEC()`, `\$SET()`

### EXISTS( topic ) -- check if topic exists

• Topic can be `TopicName` or a `Web.TopicName`
• Syntax: `\$EXISTS( topic )`
• Example: `%CALC{"\$EXISTS(WebHome)"}%` returns `1`
• Example: `%CALC{"\$EXISTS(ThisDoesNotExist)"}%` returns `0`

### FIND( string, text, start ) -- find one string within another string

• Finds one text `string`, within another `text`, and returns the number of the starting position of `string`, from the first character of `text`. This search is case sensitive and is not a regular expression search; use `\$SEARCH()` for regular expression searching. Starting position is 1; a 0 is returned if nothing is matched.
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`
>
>
• 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:
<
<
• Related: `\$SET()`, `\$SETM()`
>
>
• Related: `\$EXEC()`, `\$NOEXEC()`, `\$SET()`, `\$SETM()`

### 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:
<
<
• Related: `\$AVERAGE()`, `\$COUNTITEMS()`, `\$COUNTSTR()`, `\$DEF()`, `\$LISTIF()`, `\$LISTITEM()`, `\$LISTMAP()`, `\$LISTREVERSE()`, `\$LISTSIZE()`, `\$LISTSORT()`, `\$LISTUNIQUE()`, `\$MAX()`, `\$MEDIAN()`, `\$MIN()`, `\$PRODUCT()`, `\$SUM()`, `\$SUMDAYS()`, `\$SUMPRODUCT()`
>
>
• Related: `\$AVERAGE()`, `\$COUNTITEMS()`, `\$COUNTSTR()`, `\$DEF()`, `\$LISTIF()`, `\$LISTITEM()`, `\$LISTJOIN()`, `\$LISTMAP()`, `\$LISTREVERSE()`, `\$LISTSIZE()`, `\$LISTSORT()`, `\$LISTUNIQUE()`, `\$MAX()`, `\$MEDIAN()`, `\$MIN()`, `\$PRODUCT()`, `\$SUM()`, `\$SUMDAYS()`, `\$SUMPRODUCT()`

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

Line: 225 to 251

• Example: `%CALC{"\$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}%` returns `Kiwi`
• Related: `\$COUNTITEMS()`, `\$COUNTSTR()`, `\$LIST()`, `\$LISTIF()`, `\$LISTMAP()`, `\$LISTREVERSE()`, `\$LISTSIZE()`, `\$LISTSORT()`, `\$LISTUNIQUE()`, `\$SUM()`
>
>

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

• By default, list items are separated by a comma and a space. Use this function to indicate a specific `separator` string, which may include `\$comma` for comma, `\$n` for newline, and `\$sp` for space.
• Syntax: `\$LISTJOIN( separator, list )`
• Example: `%CALC{"\$LISTJOIN(\$n, Apple, Orange, Apple, Kiwi)"}%` returns the four items separated by new lines
• Related: `\$LIST()`, `\$LISTSIZE()`

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

• In the formula you can use `\$item` to indicate the element; `\$index` to show the index of the list, starting at 1
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:
<
<
• Related: `\$COUNTITEMS()`, `\$COUNTSTR()`, `\$LIST()`, `\$LISTIF()`, `\$LISTITEM()`, `\$LISTMAP()`, `\$LISTREVERSE()`, `\$LISTSORT()`, `\$LISTUNIQUE()`, `\$SUM()`
>
>
• Related: `\$COUNTITEMS()`, `\$COUNTSTR()`, `\$LIST()`, `\$LISTIF()`, `\$LISTITEM()`, `\$LISTJOIN()`, `\$LISTMAP()`, `\$LISTREVERSE()`, `\$LISTSORT()`, `\$LISTUNIQUE()`, `\$SUM()`

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:
<
<
• Related: `\$LIST()`, `\$MEDIAN()`, `\$MIN()`
>
>
• Related: `\$LIST()`, `\$MEDIAN()`, `\$MIN()`, `\$PERCENTILE()`

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

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

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

• Syntax: `\$MIN( list )`
• Example: `%CALC{"\$MIN(15, 3, 28)"}%` returns `3`
Changed:
<
<
• Related: `\$LIST()`, `\$MAX()`, `\$MEDIAN()`
>
>
• Related: `\$LIST()`, `\$MAX()`, `\$MEDIAN()`, `\$PERCENTILE()`

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

• Syntax: `\$MOD( num, divisor )`
• Example: `%CALC{"\$MOD(7, 3)"}%` returns `1`
Changed:
<
<
• Related: `\$EVAL()`, `\$()`
>
>
• 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 )`
• 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

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

### ODD( num ) -- test for odd number

• Syntax: `\$ODD( num )`
• Example: `%CALC{"\$ODD(2)"}%` returns `0`
• Related: `\$ABS()`, `\$EVEN()`, `\$MOD()`, `\$SIGN()`

### OR( list ) -- logcial OR of a list

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

### PERCENTILE( num, list ) -- percentile of a list or range of cells

• Calculates the num-th percentile, useful to establish a threshold of acceptance. num is the percentile value, range 0..100
• Syntax: `\$PERCENTILE( num, list )`
• Example: `%CALC{"\$PERCENTILE(75, 400, 200, 500, 100, 300)"}%` returns `450`
• Related: `\$LIST()`, `\$MAX()`, `\$MEDIAN()`, `\$MIN()`

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

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

• Related: `\$LIST()`, `\$PRODUCT()`, `\$SUM()`, `\$SUMPRODUCT()`

Changed:
<
<

>
>

### 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`

• Related: `\$LOWER()`, `\$PROPER()`, `\$TRIM()`, `\$UPPER()`

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

### 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:
<
<
• Related: `\$ABS()`, `\$EVAL()`, `\$INT()`, `\$NOT()`
>
>
• Related: `\$ABS()`, `\$EVAL()`, `\$EVEN()`, `\$INT()`, `\$NOT()`, `\$ODD()`

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))`

• Related: `\$LIST()`, `\$PRODUCT()`, `\$SUM()`

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

• Related: `\$FORMATTIME()`, `\$FORMATGMTIME()`, `\$TIME()`, `\$TIMEDIFF()`, `\$TODAY()`

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
>
>
• (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 -->`
>
>
 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 `102`, 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

Copyright � by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback