forked from SpartnerNL/Laravel-Excel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRow.php
86 lines (72 loc) · 1.82 KB
/
Row.php
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
<?php
namespace Maatwebsite\Excel;
use Illuminate\Support\Collection;
use PhpOffice\PhpSpreadsheet\Worksheet\Row as SpreadsheetRow;
class Row
{
use DelegatedMacroable;
/**
* @var array
*/
protected $headingRow = [];
/**
* @var SpreadsheetRow
*/
private $row;
/**
* @param SpreadsheetRow $row
* @param array $headingRow
*/
public function __construct(SpreadsheetRow $row, array $headingRow = [])
{
$this->row = $row;
$this->headingRow = $headingRow;
}
/**
* @return SpreadsheetRow
*/
public function getDelegate(): SpreadsheetRow
{
return $this->row;
}
/**
* @param null $nullValue
* @param bool $calculateFormulas
* @param bool $formatData
*
* @return Collection
*/
public function toCollection($nullValue = null, $calculateFormulas = false, $formatData = true): Collection
{
return new Collection($this->toArray($nullValue, $calculateFormulas, $formatData));
}
/**
* @param null $nullValue
* @param bool $calculateFormulas
* @param bool $formatData
*
* @return array
*/
public function toArray($nullValue = null, $calculateFormulas = false, $formatData = true)
{
$cells = [];
$i = 0;
foreach ($this->row->getCellIterator() as $cell) {
$value = (new Cell($cell))->getValue($nullValue, $calculateFormulas, $formatData);
if (isset($this->headingRow[$i])) {
$cells[$this->headingRow[$i]] = $value;
} else {
$cells[] = $value;
}
$i++;
}
return $cells;
}
/**
* @return int
*/
public function getIndex(): int
{
return $this->row->getRowIndex();
}
}