PHP and Javascript implementations of a simple markdown parser
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

spreadsheet.md 5.2KB

Spreadsheet Expressions

Spreadsheet expressions are an optional feature not enabled in the default parser configurations. To enable it, include spreadsheet.js and create a Markdown instance with a MDSpreadsheetReader.

Expressions

As with many spreadsheet applications, a cell that begins with = is treated as a formula.

Cell References

Values in other cells can be referenced with addresses. It consists of a column letter and an optional row number. When the row number is omitted the row is assumed to be the same as where the expression is located.

Only body rows of a table are included in calculations and can be referenced. Header rows are entirely ignored.

| Address | Description | | -- | -- | | =A1 | Value from the leftmost column on the first row | | =C2 | Value from the third column from the left on the second row | | =A | Value from the leftmost column on the same row as the expression | | =AB1 | Value from the 28th column from the left. Letters proceed A to Z for columns 1 to 26, then AA, AB, AC… for 27, 28, 29…. Limited to 2 letters (676 columns), which is way more than could ever reasonably fit in a markdown table. |

Rows or column references can be fixed for autofilled formulas (discussed below) by using a $ before the column letters or row number.

| Address | Description | | -- | -- | | =$A1 | First column and row. If transposed, the row may change but the column will not. | | =A$1 | First column and row. If transposed, the column may change but the row will not. | | =$A$1 | First column and row even if transposed. |

Operators

| Operator | Description | | -- | -- | | x + y | Addition | | x - y | Subtraction | | x * y | Multiplication | | x / y | Division | | -x | Unary minus. Negates an argument. | | x & y | Concatenate. Produces a text value. | | x < y | Less than. Produces a Boolean value. | | x <= y | Less than or equal. Produces a Boolean value. | | x > y | Greater than. Produces a Boolean value. | | x >= y | Greater than or equal. Produces a Boolean value. | | x == y | Equal. Produces a Boolean value. | | x != y | Not equal. Produces a Boolean value. | | !x | Logical not. Produces a Boolean value. |

Parentheses

Calculations can be grouped in parentheses to affect evaluation order.

| Example | Evaluation order | | -- | -- | | =3*4+1*2 | 1. =12+1*2 (multiply 3 and 4)
2. =12+2 (multiply 1 and 2)
3. =14 (add 12 and 2) | | =3*(4+1)*2 | 1. =3*5*2 (add 4 and 1)
2. =15*2 (multiply 3 and 5)
3. =30 (multiply 15 and 2) |

Functions

| Function | Description | | -- | -- | | ABS(x) | Absolute value | | AND(x, y,, z) | Boolean AND of 1 or more arguments | | AVERAGE(x, y,, z) | Statistical mean of 1 or more arguments. Non-numeric values are ignored. | | CEILING(x) | Rounds a value up | | EXP(x) | Raises e to the power of x | | FLOOR(x) | Rounds a value down | | IF(test, trueval, falseval) | Returns trueval if test evaluates to TRUE, otherwise returns falseval. | IFS(test1, val1, test2, val2,, fallbackval) | Performs multiple if tests. If test1 is TRUE, returns val1. If test2 is TRUE, returns val2. Etc. If no tests are TRUE, the final fallbackval is returned. Takes an odd number of arguments of 3 or more. | | LN(x) | Natural logarithm | | LOG(x,[ base]) | Logarithm with a given base, or 10 if base omitted | | LOWER(x) | Lowercase of a text value | | MAX(x, y,, z) | Maximum of 1 or more values | | MIN(x, y,, z) | Minimum of 1 or more values | | MOD(x, y) | Modulo division | | NOT(x) | Boolean NOT | | OR(x, y,, z) | Boolean OR of 1 or more arguments | | POWER(x, y) | Raises x to the y exponent | | ROUND(x, [digits]) | Rounds a number to the nearest integer. If digits is provided, rounds to that number of digits after the decimal place. Negative digits will round to the nearest 10, 100, etc. | | SQRT(x) | Square root | | SUBSTITUTE(text, pattern, replacement) | Replaces all occurrences of pattern in text with replacement | | SUM(x, y,, z) | Sum of 1 or more numeric arguments. Non-numeric values are ignored. | | UPPER(x) | Upercase of a text value | | XOR(x, y,, z) | Boolean XOR of 1 or more arguments |

Non-Formula Values

Values that are not formulas with recognized values (e.g. numbers, dollar amounts) will be interpreted and reformatted.

Literal Text

To force a value to behave like text, prefix it with a '. E.g. '0001 will be treated as regular text, not a number, and will not be reformatted. A text value beginning with an equal sign can be prevented from being interpreted as a formula in the same way. '=A. The leading apostrophe will be stripped when rendering the table cell. For a literal leading apostrophe, prefix with two apostrophes. ''Kay

Errors

If an expression cannot be evaluated, the cell will show an error symbol, such as #REF, #SYNTAX, or #ERROR. A more detailed message is in the title attribute and can be seen in a tooltip by mousing over it.