@@ -349,6 +349,9 @@ private function convertDateTimeInt(mixed $result): mixed
349
349
public function getCalculatedValueString (): string
350
350
{
351
351
$ value = $ this ->getCalculatedValue ();
352
+ while (is_array ($ value )) {
353
+ $ value = array_shift ($ value );
354
+ }
352
355
353
356
return ($ value === '' || is_scalar ($ value ) || $ value instanceof Stringable) ? "$ value " : '' ;
354
357
}
@@ -362,17 +365,19 @@ public function getCalculatedValueString(): string
362
365
*/
363
366
public function getCalculatedValue (bool $ resetLog = true ): mixed
364
367
{
368
+ $ title = 'unknown ' ;
365
369
if ($ this ->dataType === DataType::TYPE_FORMULA ) {
366
370
try {
367
- $ index = $ this ->getWorksheet ()->getParentOrThrow ()->getActiveSheetIndex ();
368
- $ selected = $ this ->getWorksheet ()->getSelectedCells ();
371
+ $ thisworksheet = $ this ->getWorksheet ();
372
+ $ title = $ thisworksheet ->getTitle ();
373
+ $ index = $ thisworksheet ->getParentOrThrow ()->getActiveSheetIndex ();
374
+ $ selected = $ thisworksheet ->getSelectedCells ();
369
375
$ result = Calculation::getInstance (
370
- $ this -> getWorksheet () ->getParent ()
376
+ $ thisworksheet ->getParent ()
371
377
)->calculateCellValue ($ this , $ resetLog );
372
378
$ result = $ this ->convertDateTimeInt ($ result );
373
- $ this ->getWorksheet ()->setSelectedCells ($ selected );
374
- $ this ->getWorksheet ()->getParentOrThrow ()->setActiveSheetIndex ($ index );
375
- // We don't yet handle array returns
379
+ $ thisworksheet ->setSelectedCells ($ selected );
380
+ $ thisworksheet ->getParentOrThrow ()->setActiveSheetIndex ($ index );
376
381
if (is_array ($ result ) && Calculation::getArrayReturnType () !== Calculation::RETURN_ARRAY_AS_ARRAY ) {
377
382
while (is_array ($ result )) {
378
383
$ result = array_shift ($ result );
@@ -390,21 +395,28 @@ public function getCalculatedValue(bool $resetLog = true): mixed
390
395
}
391
396
}
392
397
}
398
+ $ newColumn = $ this ->getColumn ();
393
399
if (is_array ($ result )) {
394
400
$ newRow = $ row = $ this ->getRow ();
395
401
$ column = $ this ->getColumn ();
396
402
foreach ($ result as $ resultRow ) {
397
- $ newColumn = $ column ;
398
- $ resultRowx = is_array ($ resultRow ) ? $ resultRow : [$ resultRow ];
399
- foreach ($ resultRowx as $ resultValue ) {
403
+ if (is_array ($ resultRow )) {
404
+ $ newColumn = $ column ;
405
+ foreach ($ resultRow as $ resultValue ) {
406
+ if ($ row !== $ newRow || $ column !== $ newColumn ) {
407
+ $ thisworksheet ->getCell ($ newColumn . $ newRow )->setValue ($ resultValue );
408
+ }
409
+ ++$ newColumn ;
410
+ }
411
+ ++$ newRow ;
412
+ } else {
400
413
if ($ row !== $ newRow || $ column !== $ newColumn ) {
401
- $ this -> getWorksheet ()-> getCell ($ newColumn . $ newRow )->setValue ($ resultValue );
414
+ $ thisworksheet -> getCell ($ newColumn . $ newRow )->setValue ($ resultRow );
402
415
}
403
416
++$ newColumn ;
404
417
}
405
- ++$ newRow ;
406
418
}
407
- $ this -> getWorksheet () ->getCell ($ column . $ row );
419
+ $ thisworksheet ->getCell ($ column . $ row );
408
420
}
409
421
} catch (SpreadsheetException $ ex ) {
410
422
if (($ ex ->getMessage () === 'Unable to access External Workbook ' ) && ($ this ->calculatedValue !== null )) {
@@ -414,7 +426,7 @@ public function getCalculatedValue(bool $resetLog = true): mixed
414
426
}
415
427
416
428
throw new CalculationException (
417
- $ this -> getWorksheet ()-> getTitle () . '! ' . $ this ->getCoordinate () . ' -> ' . $ ex ->getMessage (),
429
+ $ title . '! ' . $ this ->getCoordinate () . ' -> ' . $ ex ->getMessage (),
418
430
$ ex ->getCode (),
419
431
$ ex
420
432
);
0 commit comments