#csv->cells(row?: number, rows?: bool, column?: any, columns?: bool, header?: bool, as?: type) → any
セルです。単独で使うか
rows と併用すると全行を、columns と併用すると全列を返します。row: は 1 行を選びます(0 から数えます。-1 は最後の行です)。column: は 1 列を選びます(ヘッダー名または 0 から数えた位置で指定します)。row と column を同時に指定すると、交差する 1 つのセルを返します。column: と rows を使うと、すべての行のその列のセルを返します。行はヘッダー行をキーとするマップ、ヘッダーがない場合はセルのリストになります。列はヘッダー行をキーとするリストのマップ、またはリストのリストになります。ヘッダーがない場合、行ごとに長さが異なることがあり、列の取得では届かない短い行は飛ばされます。最初の行は、すべてのセルが数値でない限りヘッダーとみなされます。選ぶには header か not header を指定します。数値として書かれたセルは数値として返されます。セルはカンマ、タブ、セミコロン、または数値の間の空白で区切られることがあります。as: で型を指定すると、結果はその型に照らして確認され、変換されます。| パラメーター | 受け取るもの |
|---|---|
row 省略可 | number |
rows 省略可 | フラグです: rows または not rows |
column 省略可 | any |
columns 省略可 | フラグです: columns または not columns |
header 省略可能 | フラグ: header または not header |
as 省略可 | type |
引数には名前を付けられます: ->cells(…, rows: …, column: …)。
例
<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)