From f4dccf35f77da8aa9d39fe3082be00c501e06ab1 Mon Sep 17 00:00:00 2001 From: PeterThoeny Date: Sun, 21 Mar 2004 07:11:40 +0000 Subject: [PATCH] none --- TWiki/SpreadSheetPlugin.mdwn | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/TWiki/SpreadSheetPlugin.mdwn b/TWiki/SpreadSheetPlugin.mdwn index a172e9a..90e1ade 100644 --- a/TWiki/SpreadSheetPlugin.mdwn +++ b/TWiki/SpreadSheetPlugin.mdwn @@ -1,6 +1,6 @@ # TWiki Spreadsheet Plugin -This Plugin adds speadsheet capabilities to %WIKITOOLNAME% 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 %WIKITOOLNAME% 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: @@ -39,8 +39,9 @@ The formula next to "Total" is **%CALC\{"$SUM( $ABOVE() )"\}%**. Syntax Rules -- 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 @@ -124,24 +125,24 @@ The formula next to "Total" is **%CALC\{"$SUM( $ABOVE() )"\}%**. 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 + "$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 + "$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 + Get the value of a previously set variable. Specify the variable name (alphanumeric characters and underscores). An empty string is returned if the variable does not exist. Use $SET() to set a variable first. Unlike table ranges, variables live for the time of the page view and persist across tables, i.e. you can use it to summarize results across several tables. See also $SET(). Example: %CALC{"$GET(my_total)"}% returns the value of the my_total variable "$IF(condition, value if true, value if 0)" - Returns one value if a condition is met, and another value if not. The condition can be a number (where 0 means condition not met), or two numbers with a comparison operator < (less than), <= (less than or equal), == (equal), != (not equal), >= (greater than or equal), > (greater than). Examples:%BR% %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK )"}% returns Over Budget if value in R1:C5 is over 1000, OK if not%BR% %CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2) )"}% returns the content of R1:C2 or empty if empty%BR% %CALC{"$SET(val, $IF( $T(R1:C2) == 0, zero, $T(R1:C2) ))"}% sets a variable conditionally + 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:%BR% %CALC{"$IF( $T(R1:C5) > 1000, Over Budget, OK)"}% returns Over Budget if value in R1:C5 is over 1000, OK if not%BR% %CALC{"$IF( $EXACT($T(R1:C2),), empty, $T(R1:C2))"}% returns the content of R1:C2 or empty if empty%BR% %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 + Evaluates a simple formula and rounds the result down to the nearest integer. Example: %CALC{"$INT(10 / 4)"}% returns 2 "$LEFT()" @@ -156,6 +157,10 @@ The formula next to "Total" is **%CALC\{"$SUM( $ABOVE() )"\}%**. 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 | + "$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:%BR% %CALC{"$LISTITEM(2, Apple, Orange, Apple, Kiwi)"}% returns Orange %BR% %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 @@ -217,7 +222,7 @@ The formula next to "Total" is **%CALC\{"$SUM( $ABOVE() )"\}%**. "$PROPERSPACE(text)" - Properly spaces out [[TWiki/WikiWords]] preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE [[TWiki/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 [[Main/WebHome]] + Properly spaces out [[TWiki/WikiWords]] preceeded by white space, parenthesis, or ][. Words listed in the DONTSPACE [[TWiki/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)" @@ -383,7 +388,7 @@ Plugin settings are stored as preferences variables. To reference a plugin setti - Set SKIPINCLUDE = 1 - [[WikiWords|TWiki/WikiWord]] 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 + - Set DONTSPACE = CodeWarrior, MacDonald, McIntosh, RedHat, SuSE ## Plugin Installation Instructions @@ -419,15 +424,19 @@ Plugin settings are stored as preferences variables. To reference a plugin setti Plugin Version: - 16 Mar 2004 + 21 Mar 2004 Change History:   + 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 + 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: @@ -537,4 +546,4 @@ Plugin settings are stored as preferences variables. To reference a plugin setti **_Related Topics:_** [[TWikiPreferences]], [[TWikiPlugins]] --- TWiki:Main/PeterThoeny - 16 Mar 2004 +-- TWiki:Main/PeterThoeny - 21 Mar 2004 -- 1.9.4