TWiki home TWiki.Tukro > TWiki > SpreadSheetPlugin (r1.1 vs. r1.8) TWiki.Tukro webs:
Main | TWiki | Know | Sandbox
TWiki . { Welcome | Register | Changes | Topics | Index | Search | Go }
 <<O>>  Difference Topic SpreadSheetPlugin (r1.8 - 03 Apr 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1080980603" format="1.0" version="1.7"
>
>
META TOPICINFO PeterThoeny date="1081014633" format="1.0" version="1.8"

TWiki Spreadsheet Plugin

This Plugin adds speadsheet capabilities to TWiki.Tukro topics. Formulae like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables. In other words, this Plugin provides general formula evaluation capability, not just classic spreadsheet functions.

Changed:
<
<
Example:
>
>
Example:

Region: Sales:
Northeast 320
Line: 13 to 14

Asia 220
Total: 220
Added:
>
>
      Interactive example:

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


The formula next to "Total" is %CALC{"$SUM( $ABOVE() )"}%.
(you see the formula instead of the sum in case the Plugin is not installed or not enabled.)
Added:
>
>

Syntax Rules

Line: 58 to 74

"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
Changed:
<
<
"$LISTIF(condition, list)" Remove elements from a list that do not meet a condition. In addition to the condition described in $IF(), you can use $item to indicate the current element. Examples:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , C)"}% returns A, B, C
>
>
"$LISTIF(condition, list)" Remove elements from a list that do not meet a condition. In addition to the condition described in $IF(), you can use $item to indicate the current element, and $index for the list index, starting at 1. Examples:
%CALC{"$LISTIF($item > 12, 14, 7, 25)"}% returns 14, 25
%CALC{"$LISTIF($NOT($EXACT($item,)), A, B, , E)"}% returns non-empty elements A, B, E
%CALC{"$LISTIF($index > 2, A, B, C, D)"}% returns C, D

"$LISTITEM(index, list)" Get one element of a list. Index is 1 to size of list; use a negative number to count from the end of the list. Examples:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi
"$LISTMAP(formula, list)" Evaluate and update each element of a list. In the formula you can use $item to indicate the element; $index to show the index of the list, starting at 1. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple

 <<O>>  Difference Topic SpreadSheetPlugin (r1.7 - 03 Apr 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1079853100" format="1.0" version="1.6"
>
>
META TOPICINFO PeterThoeny date="1080980603" format="1.0" version="1.7"

TWiki Spreadsheet Plugin

This Plugin adds speadsheet capabilities to TWiki.Tukro topics. Formulae like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables. In other words, this Plugin provides general formula evaluation capability, not just classic spreadsheet functions.

Line: 37 to 37

Function Description down
"$ABOVE()" The address range of cells above the current cell
Added:
>
>
"$ABS(num)" The absolute value of a number. Example: %CALC{"$ABS(-12.5)"}% returns 12.5

"$AND(list)" The logcial AND of a list. Example: %CALC{"$AND(1, 0, 1)"}% returns 0
"$AVERAGE(list)" The average of a list or a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
Line: 47 to 48

"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
Changed:
<
<
"$FIND(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search is case sensitive and is not a regular expression search; use $SEARCH() for regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$FIND(f, fluffy)"}% returns 1
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
%CALC{"$FIND(@, fluffy, 1)"}% returns an empty string
>
>
"$FIND(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search is case sensitive and is not a regular expression search; use $SEARCH() for regular expression searching. Starting position is 1; a 0 is returned if nothing is matched. Examples:
%CALC{"$FIND(f, fluffy)"}% returns 1
%CALC{"$FIND(f, fluffy, 2)"}% returns 4
%CALC{"$FIND(@, fluffy, 1)"}% returns 0

"$FORMAT(type, prec, number)" Formats a number to a certain type and precision. Types with examples:
  - %CALC{"$FORMAT( COMMA, 2, 12345.6789 )"}% returns 12,345.68
  - %CALC{"$FORMAT( DOLLAR, 2, 12345.67 )"}% returns $12,345.68
  - %CALC{"$FORMAT( NUMBER, 1, 12345.67 )"}% returns 12345.7
  - %CALC{"$FORMAT( PERCENT, 1, 0.1234567 )"}% returns 12.3%
"$FORMATTIME(serial, text)" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME(0, $year/$month/$day GMT)"}% returns 1970/01/01 GMT
"$FORMATGMTIME(serial, text)" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME(1041379200, $day $mon $year)"}% returns 01 Jan 2003
Line: 57 to 58

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

"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
"$LISTSORT(list)" Sorts a list in ASCII order, or numerically if all elements are numeric. Example: %CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
Line: 80 to 82

"$RIGHT()" The address range of cells to the right of the current cell
"$ROUND(formula, digits)" Evaluates a simple formula and rounds the result up or down to the number of digits if digits is positive; to the nearest integer if digits is missing; or to the left of the decimal point if digits is negative. Examples:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
%CALC{"$ROUND(34.9, -1)"}% returns 30
"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
Changed:
<
<
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns an empty string
>
>
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; a 0 is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns 0

"$SET(name, value)" Set a variable for later use. Specify the variable name (alphanumeric characters and underscores) and the value. The value may contain a formula; formulas are evaluated before the variable assignment. This function returns no output. Use $GET() to retrieve variables. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables. See also $GET(). Example: %CALC{"$SET( my_total, $SUM($ABOVE()) )"}% sets the my_total variable to the sum of all table cells located above the current cell and returns an empty string
"$SETM(name, formula)" Updates an existing variable based on a formula. Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables. Example: %CALC{"$SETM( total, + $SUM($LEFT()) )"}% adds the sum of all table cells on the left to the total variable, and returns an empty string
"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1
Line: 156 to 158

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 21 Mar 2004
>
>
Plugin Version: 03 Apr 2004

Change History: <!-- specify latest version first --> 
Changed:
<
<
21 Mar 2004: Added $LISTINDEX(); fixed call to inofficial function
>
>
03 Apr 2004: Added $ABS(), $LISTIF(); fixed $VALUE() to remove leading zeros; changed $FIND() and $SEARCH() to return 0 instead of empty string if no match
21 Mar 2004: Added $LISTITEM(); fixed call to unofficial function

16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE()); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning
08 Mar 2004: Added $LIST()
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
Line: 189 to 192

Related Topics: TWikiPreferences, TWikiPlugins

Added:
>
>
-- TWiki:Main/PeterThoeny - 03 Apr 2004

 <<O>>  Difference Topic SpreadSheetPlugin (r1.6 - 21 Mar 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1079428480" format="1.0" version="1.5"
>
>
META TOPICINFO PeterThoeny date="1079853100" format="1.0" version="1.6"

TWiki Spreadsheet Plugin

Changed:
<
<
This Plugin adds speadsheet capabilities to TWiki.Tukro topics. Formulas like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables.
>
>
This Plugin adds speadsheet capabilities to TWiki.Tukro topics. Formulae like %CALC{"$INT(7/3)"}% are evaluated at page view time. They can be placed in table cells and outside of tables. In other words, this Plugin provides general formula evaluation capability, not just classic spreadsheet functions.

Example:

Line: 18 to 18

Syntax Rules

Changed:
<
<
  • The formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
>
>
The action of this Plugin is triggered by the %CALC{"..."}% variable, which gets rendered according to the built-in function(s) found between the quotes.

  • Built-in function are of format $FUNCNAME(parameter)

  • Functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
  • Functions are evaluated from left to right, and from inside to outside if nested
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
Line: 56 to 57

"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
Added:
>
>
"$LISTITEM(index, list)" Get one item of a list. Index is 1 to size of list; use a negative number to count from the end of the list. Examples:
%CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange
%CALC{"$LISTITEM(-1, Apple, Orange, Apple, Kiwi)"}% returns Kiwi

"$LISTMAP(formula, list)" Evaluate and update each element of a list. In the formla, $item indicates the element, $index the index of the list starting at 1. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
Line: 71 to 73

"$OR(list)" The logcial OR of a list. Example: %CALC{"$OR(1, 0, 1)"}% returns 1
"$PRODUCT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
Changed:
<
<
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(McIntosh likes WikiWord links like WebHome and [[WebHome][WebHome]])"}% returns McIntosh likes Wiki Word links like Web Home and Web Home
>
>
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(Old MacDonald had a ServerFarm, EeEyeEeEyeOh"}% returns Old MacDonald had a Server Farm, Ee Eye Ee Eye Oh

"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\
"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
Line: 135 to 137

  • WikiWords to exclude from being spaced out by the $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
Changed:
<
<
    • Set DONTSPACE = CodeWarrior?, McIntosh?, RedHat?, SuSE?
>
>
    • Set DONTSPACE = CodeWarrior?, MacDonald?, McIntosh?, RedHat?, SuSE?

Line: 154 to 156

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 16 Mar 2004
>
>
Plugin Version: 21 Mar 2004

Change History: <!-- specify latest version first --> 
Changed:
<
<
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE(); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning
>
>
21 Mar 2004: Added $LISTINDEX(); fixed call to inofficial function
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE()); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning

08 Mar 2004: Added $LIST()
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
27 Feb 2004: Added $COUNTUNIQUE()
Line: 186 to 189

Related Topics: TWikiPreferences, TWikiPlugins

Added:
>
>
-- TWiki:Main/PeterThoeny - 21 Mar 2004

 <<O>>  Difference Topic SpreadSheetPlugin (r1.5 - 16 Mar 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1078814460" format="1.0" version="1.4"
>
>
META TOPICINFO PeterThoeny date="1079428480" format="1.0" version="1.5"

TWiki Spreadsheet Plugin

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

Line: 43 to 43

"$COLUMN(offset)" The current column number with an optional offset
"$COUNTITEMS(list)" Counts individual items in a list. Example: %CALC{"$COUNTITEMS( $ABOVE() )"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open
"$COUNTSTR(list, str)" Counts the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list. Example: To count the number of non empty cells above the current cell, write %CALC{"$COUNTSTR( $ABOVE() )"}%; to count the number of cells equal to DONE, write %CALC{"$COUNTSTR( $ABOVE(), DONE )"}%;
Deleted:
<
<
"$COUNTUNIQUE(list)" Counts unique items in a list, separated by comma and/or space. Example: %CALC{"$COUNTUNIQUE( $ABOVE() )"}% returns Alice: 2, Mike: 1, Tom: 2 assuming the cells above the current cell contain Alice and Tom, Mike and Alice, Tom

"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
Line: 52 to 51

"$FORMATTIME( serial, text )" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME( 0, $year/$month/$day GMT )"}% returns 1970/01/01 GMT
"$FORMATGMTIME( serial, text )" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME( 1041379200, $day $mon $year )"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. Specify the variable name (alphanumeric characters and underscores). An empty string is returned if the variable does not exist. Use $SET() to set a variable first. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables. See also $SET(). Example: %CALC{"$GET( my_total )"}% returns the value of the my_total variable
Changed:
<
<
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:
%CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2) )"}% returns the content of R1:C2 or empty if empty
%CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2) ))"}% sets a variable conditionally (notice that you cannot set a variable conditionally inside an $IF() since formulae in the "value if true" and "value if 0" are both evaluated before the condition is applied)
>
>
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:
%CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2) )"}% returns the content of R1:C2 or empty if empty
%CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2) ))"}% sets a variable conditionally

"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Changed:
<
<
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
>
>
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Cells containing commas are merged into the list. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |
"$LISTMAP(formula, list)" Evaluate and update each element of a list. In the formla, $item indicates the element, $index the index of the list starting at 1. Example: %CALC{"$LISTMAP($index: $EVAL(2 * $item), 3, 5, 7, 11)"}% returns 1: 6, 2: 10, 3: 14, 4: 22
"$LISTREVERSE(list)" The opposite order of a list. Example: %CALC{"$LISTREVERSE(Apple, Orange, Apple, Kiwi)"}% returns Kiwi, Apple, Orange, Apple
"$LISTSIZE(list)" The number of elements in a list. Example: %CALC{"$LISTSIZE(Apple, Orange, Apple, Kiwi)"}% returns 4
"$LISTSORT(list)" Sorts a list in ASCII order, or numerically if all elements are numeric. Example: %CALC{"$LISTSORT(Apple, Orange, Apple, Kiwi)"}% returns Apple, Apple, Kiwi, Orange
"$LISTUNIQUE(list)" Removes all duplicates from a list. Example: %CALC{"$LISTUNIQUE(Apple, Orange, Apple, Kiwi)"}% returns Apple, Orange, Kiwi

"$LOWER(text)" The lower case string of a text. Example: %CALC{"$LOWER( $T(R1:C5) )"}% returns the lower case string of the text in cell R1:C5
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
Line: 76 to 80

"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns an empty string
"$SET(name, value)" Set a variable for later use. Specify the variable name (alphanumeric characters and underscores) and the value. The value may contain a formula; formulas are evaluated before the variable assignment. This function returns no output. Use $GET() to retrieve variables. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables. See also $GET(). Example: %CALC{"$SET( my_total, $SUM($ABOVE()) )"}% sets the my_total variable to the sum of all table cells located above the current cell and returns an empty string
Added:
>
>
"$SETM(name, formula)" Updates an existing variable based on a formula. Specify the variable name (alphanumeric characters and underscores) and the formula. The formula must start with an operator to + (add), - (subtract), * (multiply), or / (divide) something to the variable. This function returns no output. Use $GET() to retrieve variables. Example: %CALC{"$SETM( total, + $SUM($LEFT()) )"}% adds the sum of all table cells on the left to the total variable, and returns an empty string

"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1
"$SUBSTITUTE(text, old, new, instance, option)" Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r. See also $REPLACE(), $TRANSLATE(). Examples:
%CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
"$SUM(list)" The sum of a list or range of cells. Example: To sum up column 5 excluding the title row, write: %CALC{"$SUM( R2:C5..R$ROW(-1):C5 )"}% in the last row; or simply %CALC{"$SUM( $ABOVE() )"}%
Line: 149 to 154

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 08 Mar 2004
>
>
Plugin Version: 16 Mar 2004

Change History: <!-- specify latest version first --> 
Added:
>
>
16 Mar 2004: Added $LISTMAP(), $LISTREVERSE(), $LISTSIZE(), $LISTSORT(), $LISTUNIQUE(), $SETM(); retired $COUNTUNIQUE() in favor of $COUNTITEMS($LISTUNIQUE(); fixed evaluation order issue of $IF(); fixed missing eval error messages suppressed since version 06 Mar 2004; redirect stderr messages to warning

08 Mar 2004: Added $LIST()
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
27 Feb 2004: Added $COUNTUNIQUE()
Line: 180 to 186

Related Topics: TWikiPreferences, TWikiPlugins

Added:
>
>
-- TWiki:Main/PeterThoeny - 16 Mar 2004

 <<O>>  Difference Topic SpreadSheetPlugin (r1.4 - 09 Mar 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1078653879" format="1.0" version="1.3"
>
>
META TOPICINFO PeterThoeny date="1078814460" format="1.0" version="1.4"

TWiki Spreadsheet Plugin

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

Line: 56 to 56

"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Added:
>
>
"$LIST(range)" Converts the content of a range of cells into a flat list, delimited by comma. Example: %CALC{"$LIST( $LEFT() )"}% returns Apples, Lemons, Oranges, Kiwis assuming the cells to the left contain | Apples | Lemons, Oranges | Kiwis |

"$LOWER(text)" The lower case string of a text. Example: %CALC{"$LOWER( $T(R1:C5) )"}% returns the lower case string of the text in cell R1:C5
"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN(3, 9, 4, 5)"}% returns 4.5
Line: 68 to 69

"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(McIntosh likes WikiWord links like WebHome and [[WebHome][WebHome]])"}% returns McIntosh likes Wiki Word links like Web Home and Web Home
"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
Changed:
<
<
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(Hi! , 3)"}% returns Hi! Hi! Hi!
>
>
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(/\, 5)"}% returns /\/\/\/\/\

"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
"$RIGHT()" The address range of cells to the right of the current cell
"$ROUND(formula, digits)" Evaluates a simple formula and rounds the result up or down to the number of digits if digits is positive; to the nearest integer if digits is missing; or to the left of the decimal point if digits is negative. Examples:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
%CALC{"$ROUND(34.9, -1)"}% returns 30
Line: 88 to 89

"$TODAY()" Get the serialized date of today at midnight GMT. The related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT. See also $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
"$TRIM(text)" Removes all spaces from text except for single spaces between words. Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces.
"$UPPER(text)" The upper case string of a text. Example: %CALC{"$UPPER( $T(R1:C5) )"}% returns the upper case string of the text in cell R1:C5
Changed:
<
<
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:
%CALC{"$VALUE(US$1,200)"}% returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
%CALC{"$VALUE(Total: -12.5)"}% returns 12.5
>
>
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:
%CALC{"$VALUE(US$1,200)"}% returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
%CALC{"$VALUE(Total: -12.5)"}% returns -12.5

Bug Tracking Example

Line: 148 to 149

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 06 Mar 2004
>
>
Plugin Version: 08 Mar 2004

Change History: <!-- specify latest version first --> 
Added:
>
>
08 Mar 2004: Added $LIST()

06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented
27 Feb 2004: Added $COUNTUNIQUE()
24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
Line: 178 to 180

Related Topics: TWikiPreferences, TWikiPlugins

Added:
>
>
-- TWiki:Main/PeterThoeny - 08 Mar 2004

 <<O>>  Difference Topic SpreadSheetPlugin (r1.3 - 07 Mar 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1078004532" format="1.0" version="1.2"
>
>
META TOPICINFO PeterThoeny date="1078653879" format="1.0" version="1.3"

TWiki Spreadsheet Plugin

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

Line: 20 to 20

  • The formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
Changed:
<
<
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
>
>
  • Functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%
  • Functions are evaluated from left to right, and from inside to outside if nested

  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. %CALC{"$SUM( 3, 5, 7 )"}%
  • A table cell can be addressed as R1:C1. Table address matrix:
Line: 35 to 36

Function Description
"$ABOVE()" The address range of cells above the current cell
Changed:
<
<
"$AVERAGE(list)" The average of the content of a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%
>
>
"$AND(list)" The logcial AND of a list. Example: %CALC{"$AND(1, 0, 1)"}% returns 0
"$AVERAGE(list)" The average of a list or a range of cells. Example: To get the average of column 5 excluding the title row, write in the last row: %CALC{"$AVERAGE( R2:C5..R$ROW(-1):C5 )"}%

"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
"$CODE(text)" The ASCII numeric value of the first character in text. Example: %CALC{"$CODE(abc)"}% returns 97
"$COLUMN(offset)" The current column number with an optional offset
Line: 50 to 52

"$FORMATTIME( serial, text )" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME( 0, $year/$month/$day GMT )"}% returns 1970/01/01 GMT
"$FORMATGMTIME( serial, text )" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME( 1041379200, $day $mon $year )"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. Specify the variable name (alphanumeric characters and underscores). An empty string is returned if the variable does not exist. Use $SET() to set a variable first. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables. See also $SET(). Example: %CALC{"$GET( my_total )"}% returns the value of the my_total variable
Changed:
<
<
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Example: %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
>
>
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:
%CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
%CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2) )"}% returns the content of R1:C2 or empty if empty
%CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2) ))"}% sets a variable conditionally (notice that you cannot set a variable conditionally inside an $IF() since formulae in the "value if true" and "value if 0" are both evaluated before the condition is applied)

"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Line: 58 to 60

"$MAX(list)" The biggest value of a list or range of cells. Example: To find the biggest number to the left of the current cell, write: %CALC{"$MAX( $LEFT() )"}%
"$MEDIAN(list)" The median of a list or range of cells. Example: %CALC{"$MEDIAN( 3, 9, 4, 5 )"}% returns 4.5
"$MIN(list)" The smallest value of a list or range of cells. Example: %CALC{"$MIN( 15, 3, 28 )"}% returns 3
Changed:
<
<
"$MULT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$MULT($LEFT())"}%
>
>
"$MOD(num, divisor)" The reminder after dividing num by divisor. Example: %CALC{"$MOD(7, 3)"}% returns 1

"$NOP(text)" A no-operation. Allows one to defy the order of Plugin execution. For example, it will allow preprossing to be done before %SEARCH{}% is evaluated. Use $per to escape '%'.
Added:
>
>
"$NOT(num)" The reverse logic of a number. Returns 0 if num is not zero, 1 if zero. Example: %CALC{"$NOT(0)"}% returns 1
"$OR(list)" The logcial OR of a list. Example: %CALC{"$OR(1, 0, 1)"}% returns 1
"$PRODUCT(list)" The product of a list or range of cells. Example: to calculate the product of the cells to the left of the current one use %CALC{"$PRODUCT($LEFT())"}%
"$PROPER(text)" Capitalizes letters in text that follow any character other than a letter. Converts all other letters to lowercase letters. Examples:
%CALC{"PROPER(a small STEP)"}% returns A Small Step
%CALC{"PROPER(f1 (formula-1))"}% returns F1 (Formula 1)
"$PROPERSPACE(text)" Properly spaces out WikiWords preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE TWikiPreferences variable or DONTSPACE Plugins setting are excluded. Example, assuming DONTSPACE contains McIntosh: %CALC{"PROPERSPACE(McIntosh likes WikiWord links like WebHome and [[WebHome][WebHome]])"}% returns McIntosh likes Wiki Word links like Web Home and Web Home
"$RAND(max)" Random number, evenly distributed between 0 and max, or 0 and 1 if max is not specified.
"$REPEAT(text)" Repeat text a number of times. Example: %CALC{"$REPEAT(Hi! , 3)"}% returns Hi! Hi! Hi!

"$REPLACE(text, start_num, num_chars, new_text)" Replaces part of text string text, based on the starting position start_num, and the number of characters to replace num_chars. The characters are replaced with new_text. Starting position is 1; use a negative start_num to count from the end of the text. See also $SUBSTITUTE(), $TRANSLATE(). Example:
%CALC{"$REPLACE(abcdefghijk,6,5,*)"}% returns abcde*k
"$RIGHT()" The address range of cells to the right of the current cell
Changed:
<
<
"$ROUND(formula)" Evaluates a simple formula and rounds the result up or down to the nearest integer. Example: %CALC{"$INT( 10 / 6 )"}% returns 2
>
>
"$ROUND(formula, digits)" Evaluates a simple formula and rounds the result up or down to the number of digits if digits is positive; to the nearest integer if digits is missing; or to the left of the decimal point if digits is negative. Examples:
%CALC{"$ROUND(3.15, 1)"}% returns 3.2
%CALC{"$ROUND(3.149, 1)"}% returns 3.1
%CALC{"$ROUND(-2.475, 2)"}% returns -2.48
%CALC{"$ROUND(34.9, -1)"}% returns 30

"$ROW(offset)" The current row number with an offset. Example: To get the number of rows excluding table heading ( first row) and summary row (last row you are in), write: %CALC{"$ROW(-2)"}%
"$SEARCH(search_string, text, start_index)" Finds one text string search_string, within another text string text, and returns the number of the starting position of search_string, from the first character of text. This search a RegularExpression search; use $FIND() for non-regular expression searching. Starting position is 1; an empty string is returned if nothing is matched. Examples:
%CALC{"$SEARCH([uy], fluffy)"}% returns 3
%CALC{"$SEARCH([uy], fluffy, 3)"}% returns 6
%CALC{"$SEARCH([abc], fluffy,)"}% returns an empty string
"$SET(name, value)" Set a variable for later use. Specify the variable name (alphanumeric characters and underscores) and the value. The value may contain a formula; formulas are evaluated before the variable assignment. This function returns no output. Use $GET() to retrieve variables. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables. See also $GET(). Example: %CALC{"$SET( my_total, $SUM($ABOVE()) )"}% sets the my_total variable to the sum of all table cells located above the current cell and returns an empty string
Added:
>
>
"$SIGN(num)" The sign of a number. Returns -1 if num is negative, 0 if zero, or 1 if positive. Example: %CALC{"$SIGN(-12.5)"}% returns -1

"$SUBSTITUTE(text, old, new, instance, option)" Substitutes new text for old text in a text string. instance specifies which occurance of old you want to replace. If you specify instance, only that instance is replaced. Otherwise, every occurance is changed to the new text. A literal search is performed by default; a RegularExpression search if the option is set to r. See also $REPLACE(), $TRANSLATE(). Examples:
%CALC{"$SUBSTITUTE(Good morning, morning, day)"}% returns Good day
%CALC{"$SUBSTITUTE(Q2-2002,2,3)"}% returns Q3-3003
%CALC{"$SUBSTITUTE(Q2-2002,2,3,3)"}% returns Q2-2003
%CALC{"$SUBSTITUTE(abc123def,[0-9],9,,r)"}% returns abc999def
"$SUM(list)" The sum of a list or range of cells. Example: To sum up column 5 excluding the title row, write: %CALC{"$SUM( R2:C5..R$ROW(-1):C5 )"}% in the last row; or simply %CALC{"$SUM( $ABOVE() )"}%
"$SUMDAYS(list)" The total number of days in a list or range of cells containing numbers of hours, days or weeks. The default unit is days; units are indicated by a h, hours, d, days, w, weeks suffix. One week is assumed to have 5 working days, one day 8 hours. Example: %CALC{"$SUMDAYS( 2w, 1, 2d, 4h )"}% returns 13.5, the evaluation of (2*5 + 1 + 2 + 4/8)
Line: 78 to 88

"$TODAY()" Get the serialized date of today at midnight GMT. The related $TIME() returns the serialized date of today at the current time, e.g. it includes the number of seconds since midnight GMT. See also $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$TODAY()"}% returns the number of seconds since Epoch
"$TRIM(text)" Removes all spaces from text except for single spaces between words. Example: %CALC{"$TRIM( eat  spaces  )"}% returns eat spaces.
"$UPPER(text)" The upper case string of a text. Example: %CALC{"$UPPER( $T(R1:C5) )"}% returns the upper case string of the text in cell R1:C5
Added:
>
>
"$VALUE(text)" Extracts a number from text. Returns 0 if not found. Examples:
%CALC{"$VALUE(US$1,200)"}% returns 1200
%CALC{"$VALUE(PrjNotebook1234)"}% returns 1234
%CALC{"$VALUE(Total: -12.5)"}% returns 12.5

Bug Tracking Example

Line: 102 to 113

Above table is created manually. Another Plugin could build the table dynamically, e.g. by pulling data out of a bug tracking system. The Spreadsheet Plugin can be used to display table data statistics.

Changed:
<
<

SpreadSheetPlugin Settings

>
>

Plugin Settings


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

Line: 116 to 127

  • Do not handle %CALC{}% tag in included topic while including topic: (default: 1)
    • Set SKIPINCLUDE = 1
Added:
>
>
  • WikiWords to exclude from being spaced out by the $PROPERSPACE(text) function. This comma delimited list can be overloaded by a DONTSPACE preferences variable:
    • Set DONTSPACE = CodeWarrior, McIntosh, RedHat, SuSE

Plugin Installation Instructions

Line: 132 to 148

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 27 Feb 2004
>
>
Plugin Version: 06 Mar 2004

Change History: <!-- specify latest version first --> 
Added:
>
>
06 Mar 2004: Added $AND(), $MOD(), $NOT(), $OR(), $PRODUCT(), $PROPER(), $PROPERSPACE(), $RAND(), $REPEAT(), $SIGN(), $VALUE(); added digits parameter to $ROUND(); renamed $MULT() to $PRODUCT(); $MULT() is deprecated and undocumented

27 Feb 2004: Added $COUNTUNIQUE()
24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
21 Oct 2003: Added support for lists (1, 2, 3) and lists of table ranges (R1:C1..R1:C5, R3:C1..R3:C5) for all functions that accept a table range; added $TIMEADD(); in $TIMEDIFF() added week unit; in $FORMATTIME() changed $weekday to $wd and added $wday and $weekday
Line: 161 to 178

Related Topics: TWikiPreferences, TWikiPlugins

Added:
>
>
-- TWiki:Main/PeterThoeny - 06 Mar 2004

 <<O>>  Difference Topic SpreadSheetPlugin (r1.2 - 28 Feb 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1071216233" format="1.0" version="1.1"
>
>
META TOPICINFO PeterThoeny date="1078004532" format="1.0" version="1.2"

TWiki Spreadsheet Plugin

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

Line: 20 to 20

  • The formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
Changed:
<
<
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COL(0)..R$ROW(-1):C$COL(0) )"}%
>
>
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COLUMN(0)..R$ROW(-1):C$COLUMN(0) )"}%

  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. %CALC{"$SUM( 3, 5, 7 )"}%
  • A table cell can be addressed as R1:C1. Table address matrix:
Line: 39 to 39

"$CHAR(number)" The ASCII character represented by number. Example: %CALC{"$CHAR(97)"}% returns a
"$CODE(text)" The ASCII numeric value of the first character in text. Example: %CALC{"$CODE(abc)"}% returns 97
"$COLUMN(offset)" The current column number with an optional offset
Changed:
<
<
"$COUNTITEMS(list)" The count of individual items in a list. Example: To count the items of all cells above the current cell, write %CALC{"$COUNTITEMS( $ABOVE() )"}%
>
>
"$COUNTITEMS(list)" Counts individual items in a list. Example: %CALC{"$COUNTITEMS( $ABOVE() )"}% returns Closed: 1, Open: 2 assuming one cell above the current cell contains Closed and two cells contain Open

"$COUNTSTR(list, str)" Counts the number of cells in a list equal to a given string (if str is specified), or counts the number of non empty cells in a list. Example: To count the number of non empty cells above the current cell, write %CALC{"$COUNTSTR( $ABOVE() )"}%; to count the number of cells equal to DONE, write %CALC{"$COUNTSTR( $ABOVE(), DONE )"}%;
Added:
>
>
"$COUNTUNIQUE(list)" Counts unique items in a list, separated by comma and/or space. Example: %CALC{"$COUNTUNIQUE( $ABOVE() )"}% returns Alice: 2, Mike: 1, Tom: 2 assuming the cells above the current cell contain Alice and Tom, Mike and Alice, Tom

"$DEF(list)" Returns the first list item or cell reference that is not empty. Example: %CALC{"$DEF( R1:C1..R1:C3 )"}%
"$EVAL(formula)" Evaluates a simple formula. Only addition, substraction, multiplication, division and modulus of numbers are supported. Any nesting is permitted. Example: %CALC{"$EVAL( (5 * 3) / 2 + 1.1 )"}% returns 8.6
"$EXACT(text1, text2)" Compares two text strings and returns 1 if they are exactly the same, or 0 if not. Example: %CALC{"$EXACT( foo, Foo )"}% returns 0; %CALC{"$EXACT( foo, $LOWER(Foo) )"}% returns 1
Line: 49 to 50

"$FORMATTIME( serial, text )" Convert a serialized date into a date string; the following variables in text are expanded: $second (seconds, 00..59); $minute (minutes, 00..59); $hour (hours, 00..23); $day (day of month, 01..31); $month (month, 01..12); $mon (month in text format, Jan..Dec); $year (4 digit year, 1999); $ye (2 digit year, 99), $wd (day number of the week, 1 for Sunday, 2 for Monday, etc), $wday (day of the week, Sun..Sat), $weekday (day of the week, Sunday..Saturday), $yearday (day of the year, 1..365, or 1..366 in leap years). Date is assumed to be server time; add GMT to indicate Greenwich time zone. See also $TIME(), $TODAY(), $FORMATGMTIME(), $TIMEDIFF(). Example: %CALC{"$FORMATTIME( 0, $year/$month/$day GMT )"}% returns 1970/01/01 GMT
"$FORMATGMTIME( serial, text )" Convert a serialized date into a date string in Greenwich time zone. Same variables expansion as in $FORMATTIME(). Example: %CALC{"$FORMATGMTIME( 1041379200, $day $mon $year )"}% returns 01 Jan 2003
"$GET(name)" Get the value of a previously set variable. Specify the variable name (alphanumeric characters and underscores). An empty string is returned if the variable does not exist. Use $SET() to set a variable first. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables. See also $SET(). Example: %CALC{"$GET( my_total )"}% returns the value of the my_total variable
Changed:
<
<
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less then), <= (less then or equal), == (equal), != (not equal), >= (greater then or equal), >= (greater then). Example: %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not
>
>
"$IF(condition, value if true, value if 0)" Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Example: %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not

"$INT(formula)" Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT( 10 / 4 )"}% returns 2
"$LEFT()" The address range of cells to the left of the current cell
"$LENGTH(text)" The length in bytes of text. Example: %CALC{"$LENGTH(abcd)"}% returns 4
Line: 131 to 132

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Changed:
<
<
Plugin Version: 24 Oct 2003
>
>
Plugin Version: 27 Feb 2004

Change History: <!-- specify latest version first --> 
Added:
>
>
27 Feb 2004: Added $COUNTUNIQUE()

24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
21 Oct 2003: Added support for lists (1, 2, 3) and lists of table ranges (R1:C1..R1:C5, R3:C1..R3:C5) for all functions that accept a table range; added $TIMEADD(); in $TIMEDIFF() added week unit; in $FORMATTIME() changed $weekday to $wd and added $wday and $weekday
14 Oct 2003: Added $TIME(), $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF()
Line: 151 to 153

16 Apr 2001: Fixed div by 0 bug in $AVERAGE
17 Mar 2001: Initial version
CPAN Dependencies: none
Added:
>
>
TWiki:Plugins/Benchmark: GoodStyle 99%, FormattedSearch 99%, SpreadSheetPlugin 95%

Other Dependencies: none
Perl Version: 5.000 and up
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin
Line: 158 to 161

Related Topics: TWikiPreferences, TWikiPlugins

Added:
>
>
-- TWiki:Main/PeterThoeny - 27 Feb 2004

 <<O>>  Difference Topic SpreadSheetPlugin (r1.1 - 12 Dec 2003 - PeterThoeny)
Line: 1 to 1
Added:
>
>
META TOPICINFO PeterThoeny date="1071216233" format="1.0" version="1.1"

TWiki Spreadsheet Plugin

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

Example:

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

The formula next to "Total" is %CALC{"$SUM( $ABOVE() )"}%.
(you see the formula instead of the sum in case the Plugin is not installed or not enabled.)

Syntax Rules

  • The formula in the %CALC{"formula"}% variable can contain built-in functions
  • Built-in function are of format $FUNCNAME(parameter)%
  • Built-in functions may be nested, e.g. %CALC{"$SUM( R2:C$COL(0)..R$ROW(-1):C$COL(0) )"}%
  • The function parameter can be text; a mathematical formula; a cell address; or a range of cell addresses
  • Multiple parameters form a list; they are separated by a comma, followed by optional space, e.g. %CALC{"$SUM( 3, 5, 7 )"}%
  • A table cell can be addressed as R1:C1. Table address matrix:
    R1:C1 R1:C2 R1:C3 R1:C4
    R2:C1 R2:C2 R2:C3 R2:C4
  • A table cell range is defined by two cell addresses separated by "..", e.g. "row 1 through 20, column 3" is: R1:C3..R20:C3
  • Lists can refer to values and/or table cell ranges, e.g. %CALC{"$SUM( 3, 5, $T(R1:C7), R1:C11..R1:C15 )"}%
  • Formulae can only reference cells in the current or preceeding row of the current table; they may not reference cells below the current table row
  • Formulae can also be placed outside of tables; they can reference cells in the preceeding table

Built-in Functions

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

Bug Tracking Example

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

The last row is defined as:

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

Above table is created manually. Another Plugin could build the table dynamically, e.g. by pulling data out of a bug tracking system. The Spreadsheet Plugin can be used to display table data statistics.

SpreadSheetPlugin Settings

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

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

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

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

Plugin Installation Instructions

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

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

Plugin Info

Plugin Author: TWiki:Main/PeterThoeny
Plugin Version: 24 Oct 2003
Change History: <!-- specify latest version first --> 
24 Oct 2003: Added $SET(), $GET(), $MEDIAN(); added $SUMPRODUCT(), inspired by TWiki:Main/RobertWithrow; added $SUMDAYS(), contributed by TWiki:Main/SvenDowideit
21 Oct 2003: Added support for lists (1, 2, 3) and lists of table ranges (R1:C1..R1:C5, R3:C1..R3:C5) for all functions that accept a table range; added $TIMEADD(); in $TIMEDIFF() added week unit; in $FORMATTIME() changed $weekday to $wd and added $wday and $weekday
14 Oct 2003: Added $TIME(), $TODAY(), $FORMATTIME(), $FORMATGMTIME(), $TIMEDIFF()
13 Oct 2003: Added $MULT(), contributed by TWiki:Main/GerritJanBaarda
30 Jul 2003: Added $TRANSLATE()
19 Jul 2003: Added $FIND(), $NOP(), $REPLACE(), $SEARCH(), $SUBSTITUTE(), contributed by TWiki:Main/PaulineCheung
19 Apr 2003: Added $COUNTSTR(), $EXACT(), $IF(), $ROUND(), $TRIM(); added $FORMAT(), contributed by TWiki:Main/JimStraus; support % modulus operator in $EVAL, $INT, and $ROUND; fixed bug in $DEF
07 Jun 2002: Added $DEF(), contributed by TWiki:Main/MartinFuzzey; allow values with HTML formatting like <u>102</u>, suggested by TWiki:Main/GladeDiviney; added SKIPINCLUDE setting
12 Mar 2002: Support for multiple functions per nesting level
15 Jan 2002: Added $CHAR(), $CODE() and $LENGTH()
12 Nov 2001: Added $RIGHT()
12 Aug 2001: Fixed bug of disappearing multi-column cells
19 Jul 2001: Fixed incorrect $SUM calculation of cell with value 0
14 Jul 2001: Changed to plug & play
01 Jun 2001: Fixed insecure dependencies for $MIN and $MAX
16 Apr 2001: Fixed div by 0 bug in $AVERAGE
17 Mar 2001: Initial version
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.000 and up
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/SpreadSheetPluginDev

Related Topics: TWikiPreferences, TWikiPlugins

-- TWiki:Main/PeterThoeny - 24 Oct 2003



Topic SpreadSheetPlugin . { View | Diffs | r1.8 | > | r1.7 | > | r1.6 | More }
Revision r1.1 - 12 Dec 2003 - 08:03 - PeterThoeny
Revision r1.8 - 03 Apr 2004 - 17:50 - PeterThoeny
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki.Tukro? Send feedback.