#csv->cells(row?: number, rows?: bool, column?: any, columns?: bool, header?: bool, as?: type) → any
Its cells. On its own, or with
rows, every row; with columns, every column. row: picks one row, counted from 0 (-1 is the last); column: picks one column, named by its header or counted from 0. A row and a column together give the one cell where they meet, and rows with column: gives every row's cell in that column. Rows are maps keyed by the header line, or lists of cells when there isn't one; columns are a map of lists keyed by the header line, or a list of lists. Without a header, rows may be different lengths: a column skips the rows too short to reach it. The first line is a header unless every cell on it is a number: say header or not header to choose. Cells written as numbers come out as numbers. Cells may be split by commas, tabs, semicolons, or spaces between numbers. With as: a type, the result is checked and turned into it.| Parameter | Takes |
|---|---|
row optional | number |
rows optional | a flag: rows or not rows |
column optional | any |
columns optional | a flag: columns or not columns |
header optional | a flag: header or not header |
as optional | type |
Arguments can be named: ->cells(…, rows: …, column: …).
Example
<let name="prices" value="```csv
fruit,price
apple,3
plum,5
```" />
<!-- 'apple': the header line names each row's keys -->
<echo>{ $prices->cells(row: 0).fruit }</echo>
<!-- [3, 5]: the cells under the price header, as numbers -->
<echo>{ $prices->cells(column: 'price') }</echo>
<!-- 5: row 1 is plum, and its price is 5 -->
<echo>{ $prices->cells(row: 1, column: 'price') }</echo>
<!-- { fruit: ['apple', 'plum'], price: [3, 5] }: every column, keyed by its header -->
<echo>{ $prices->cells(columns) }</echo>
<let name="readings" value="```csv
387
942
945
```" />
<!-- 2274: every line is a number, so there's no header and every line is a row -->
<echo>{ $readings->cells(column: 0)->sum() }</echo>
<let name="puzzle" value="```csv
-903 -642 446
200 818
```" />
<!-- [-903, -642, 446]: spaces split the numbers on each line -->
<echo>{ $puzzle->cells(row: 0) }</echo>
<!-- [[-903, 200], [-642, 818], [446]]: the second row is too short for the third column -->
<echo>{ $puzzle->cells(columns) }</echo>$prices = ```csv
fruit,price
apple,3
plum,5
```
// 'apple': the header line names each row's keys
echo $prices->cells(row: 0).fruit
// [3, 5]: the cells under the price header, as numbers
echo $prices->cells(column: 'price')
// 5: row 1 is plum, and its price is 5
echo $prices->cells(row: 1, column: 'price')
// { fruit: ['apple', 'plum'], price: [3, 5] }: every column, keyed by its header
echo $prices->cells(columns)
$readings = ```csv
387
942
945
```
// 2274: every line is a number, so there's no header and every line is a row
echo $readings->cells(column: 0)->sum()
$puzzle = ```csv
-903 -642 446
200 818
```
// [-903, -642, 446]: spaces split the numbers on each line
echo $puzzle->cells(row: 0)
// [[-903, 200], [-642, 818], [446]]: the second row is too short for the third column
echo $puzzle->cells(columns)