@@ -160,15 +160,16 @@ private function createExcel(): void
160
160
// Loop over all cells in a row
161
161
$ colIndex = 1 ;
162
162
foreach ($ row ->getCells () as $ cell ) {
163
- $ excelCellIndex = Helper::colLetter ($ colIndex ).$ rowIndex ;
164
163
165
- // Skip cells withing merge range
164
+ // Skip cells within merged range
165
+ $ excelCellIndex = Helper::colLetter ($ colIndex ).$ rowIndex ;
166
166
while ($ this ->isMerged ($ sheet , $ excelCellIndex )) {
167
167
$ colIndex ++;
168
168
$ excelCellIndex = Helper::colLetter ($ colIndex ).$ rowIndex ;
169
169
$ sheet ->cell ($ excelCellIndex );
170
170
}
171
171
172
+ // Write cell
172
173
$ cellStyles = $ this ->getStyles ($ cell );
173
174
$ sheet ->writeCell (
174
175
trim ($ cell ->getValue ()),
@@ -188,21 +189,16 @@ private function createExcel(): void
188
189
$ sheet ->addNote (Excel::cellAddress ($ rowIndex , $ colIndex ), $ cellComment );
189
190
}
190
191
192
+ // Merge cells, if necessary
191
193
$ colspan = $ cell ->getAttribute ('colspan ' );
192
194
$ rowspan = $ cell ->getAttribute ('rowspan ' );
193
195
194
196
if ($ colspan || $ rowspan ) {
195
- if ($ colspan ) {
196
- $ colspan = $ colspan - 1 ;
197
- }
198
-
199
- if ($ rowspan ) {
200
- $ rowspan = $ rowspan - 1 ;
201
- }
197
+ $ colspan = $ colspan ? $ colspan - 1 : 0 ;
198
+ $ rowspan = $ rowspan ? $ rowspan - 1 : 0 ;
202
199
203
200
$ mergeCellsTargetCellIndex = Helper::colLetter ($ colIndex + $ colspan ).($ rowIndex + $ rowspan );
204
-
205
- $ sheet ->mergeCells ($ excelCellIndex .': ' .$ mergeCellsTargetCellIndex );
201
+ $ sheet ->mergeCells ($ excelCellIndex . ': ' . $ mergeCellsTargetCellIndex );
206
202
}
207
203
208
204
$ colIndex ++;
0 commit comments