# Source

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268``` ``` The spreadsheet directive — rstSpreadsheet v0.1.2 documentation

eq : cell equations
A Cell equation per each line.
setup : python code (optional)
Python code to be executed before evaluation cell equations.
format : number: fmt [, number: fmt, ...] (optional)
Comma separated list of the pair of number and format for showing the result of the cell equation.

Cell equation

Cell equation has the shape like this:

{NUM} = STATEMENT

or:

{NUM:CONDITION} = STATEMENT

More precisely, the syntax of the cell equation is the following:

eq                     ::=  lhs "=" rhs lhs                    ::=  "{" integer [ ":" condition ] "}" rhs                    ::=  expression_stmt_format condition              ::=  expression_stmt integer                ::=  <see python document> expression_stmt        ::=  <see python document> expression_stmt_format ::=  <expression_stmt with the format string>

expression_stmt_format is as same as expression_stmt except for that it will be formatted by the python’s str.format function and then used as a python expression. Defined fields are the integers which represent the index of the columns. For example, {0} will be replaced by the 0-th cell of the current row.

Note

Current version of rstSpreadsheet cannot parse the condition which has { or } in it.

Special variables

rstSpreadsheet provides the following special variables. You can use these in the cell equation. Note that you can override these variables by variables in :setup:.

col

This stores the above cells of the current column. Thus, col[-1] means the previous cell.

An iterative class with convenient cast functions

>>> col = ListLike(['1', '2', '3']) >>> col ListLike(['1', '2', '3']) >>> ', '.join(col) '1, 2, 3' >>> col.str ['1', '2', '3'] >>> col.int [1, 2, 3] >>> col.float [1.0, 2.0, 3.0]
str

Access the stored data as a list of strings (original data)

int

Access the stored data as a list of ints

float

Access the stored data as a list of floats

sum(type='float')

Get the sum of the stored data

>>> col = ListLike(['1', '2', '3']) >>> col.sum('int') 6
mean()

Get the mean of the stored data

>>> col = ListLike(['1', '2', '3']) >>> col.mean() 2.0
cols

A variable to access all :py:data`col`. If the current column is 1, col is as same as cols[1].

i

Index of the current row.

last

Index of the last row. This is useful in the condition.

{1:i<last} = i {1:i==last} = sum(col.int)