22
33namespace Maatwebsite \Excel ;
44
5+ use ArrayAccess ;
56use Illuminate \Support \Collection ;
67use PhpOffice \PhpSpreadsheet \Worksheet \Row as SpreadsheetRow ;
78
8- class Row
9+ class Row implements ArrayAccess
910{
1011 use DelegatedMacroable;
1112
@@ -17,7 +18,12 @@ class Row
1718 /**
1819 * @var SpreadsheetRow
1920 */
20- private $ row ;
21+ protected $ row ;
22+
23+ /**
24+ * @var array|null
25+ */
26+ protected $ rowCache ;
2127
2228 /**
2329 * @param SpreadsheetRow $row
@@ -61,6 +67,10 @@ public function toCollection($nullValue = null, $calculateFormulas = false, $for
6167 */
6268 public function toArray ($ nullValue = null , $ calculateFormulas = false , $ formatData = true , ?string $ endColumn = null )
6369 {
70+ if (is_array ($ this ->rowCache )) {
71+ return $ this ->rowCache ;
72+ }
73+
6474 $ cells = [];
6575
6676 $ i = 0 ;
@@ -76,6 +86,8 @@ public function toArray($nullValue = null, $calculateFormulas = false, $formatDa
7686 $ i ++;
7787 }
7888
89+ $ this ->rowCache = $ cells ;
90+
7991 return $ cells ;
8092 }
8193
@@ -86,4 +98,24 @@ public function getIndex(): int
8698 {
8799 return $ this ->row ->getRowIndex ();
88100 }
101+
102+ public function offsetExists ($ offset )
103+ {
104+ return isset (($ this ->toArray ())[$ offset ]);
105+ }
106+
107+ public function offsetGet ($ offset )
108+ {
109+ return ($ this ->toArray ())[$ offset ];
110+ }
111+
112+ public function offsetSet ($ offset , $ value )
113+ {
114+ //
115+ }
116+
117+ public function offsetUnset ($ offset )
118+ {
119+ //
120+ }
89121}
0 commit comments