@@ -1145,11 +1145,15 @@ private function writeSheetData(XMLWriter $objWriter, PhpspreadsheetWorksheet $w
1145
1145
// Highest row number
1146
1146
$ highestRow = $ worksheet ->getHighestRow ();
1147
1147
1148
- // Loop through cells
1148
+ // Loop through cells building a comma-separated list of the columns in each row
1149
+ // This is a trade-off between the memory usage that is required for a full array of columns,
1150
+ // and execution speed
1151
+ /** @var array<int, string> $cellsByRow */
1149
1152
$ cellsByRow = [];
1150
1153
foreach ($ worksheet ->getCoordinates () as $ coordinate ) {
1151
- $ cellAddress = Coordinate::coordinateFromString ($ coordinate );
1152
- $ cellsByRow [$ cellAddress [1 ]][] = $ coordinate ;
1154
+ [$ column , $ row ] = Coordinate::coordinateFromString ($ coordinate );
1155
+ $ cellsByRow [$ row ] = $ cellsByRow [$ row ] ?? '' ;
1156
+ $ cellsByRow [$ row ] .= "{$ column }, " ;
1153
1157
}
1154
1158
1155
1159
$ currentRow = 0 ;
@@ -1195,9 +1199,12 @@ private function writeSheetData(XMLWriter $objWriter, PhpspreadsheetWorksheet $w
1195
1199
1196
1200
// Write cells
1197
1201
if (isset ($ cellsByRow [$ currentRow ])) {
1198
- foreach ($ cellsByRow [$ currentRow ] as $ cellAddress ) {
1202
+ // We have a comma-separated list of column names (with a trailing entry); split to an array
1203
+ $ columnsInRow = explode (', ' , $ cellsByRow [$ currentRow ]);
1204
+ array_pop ($ columnsInRow );
1205
+ foreach ($ columnsInRow as $ column ) {
1199
1206
// Write cell
1200
- $ this ->writeCell ($ objWriter , $ worksheet , $ cellAddress , $ aFlippedStringTable );
1207
+ $ this ->writeCell ($ objWriter , $ worksheet , "{ $ column }{ $ currentRow }" , $ aFlippedStringTable );
1201
1208
}
1202
1209
}
1203
1210
0 commit comments