@@ -176,16 +176,21 @@ public function getValue()
176
176
177
177
/**
178
178
* Get cell value with formatting.
179
- *
180
- * @return string
181
179
*/
182
- public function getFormattedValue ()
180
+ public function getFormattedValue (): string
183
181
{
184
- return (string ) NumberFormat::toFormattedString (
182
+ $ currentCalendar = SharedDate::getExcelCalendar ();
183
+ SharedDate::setExcelCalendar ($ this ->getWorksheet ()->getParent ()->getExcelCalendar ());
184
+
185
+ $ formattedValue = (string ) NumberFormat::toFormattedString (
185
186
$ this ->getCalculatedValue (),
186
187
$ this ->getStyle ()
187
188
->getNumberFormat ()->getFormatCode ()
188
189
);
190
+
191
+ SharedDate::setExcelCalendar ($ currentCalendar );
192
+
193
+ return $ formattedValue ;
189
194
}
190
195
191
196
/**
@@ -342,8 +347,6 @@ public function setValueExplicit($value, $dataType, bool $isArrayFormula = false
342
347
break ;
343
348
default :
344
349
throw new Exception ('Invalid datatype: ' . $ dataType );
345
-
346
- break ;
347
350
}
348
351
349
352
// set the datatype
@@ -402,6 +405,9 @@ private function processArrayResult(
402
405
public function getCalculatedValue (bool $ asArray = false , bool $ resetLog = true )
403
406
{
404
407
if ($ this ->dataType === DataType::TYPE_FORMULA ) {
408
+ $ currentCalendar = SharedDate::getExcelCalendar ();
409
+ SharedDate::setExcelCalendar ($ this ->getWorksheet ()->getParent ()->getExcelCalendar ());
410
+
405
411
try {
406
412
$ coordinate = $ this ->getCoordinate ();
407
413
$ worksheet = $ this ->getWorksheet ();
@@ -430,6 +436,7 @@ public function getCalculatedValue(bool $asArray = false, bool $resetLog = true)
430
436
$ this ->getWorksheet ()->setSelectedCells ($ selected );
431
437
$ this ->getWorksheet ()->getParent ()->setActiveSheetIndex ($ index );
432
438
} catch (Exception $ ex ) {
439
+ SharedDate::setExcelCalendar ($ currentCalendar );
433
440
if (($ ex ->getMessage () === 'Unable to access External Workbook ' ) && ($ this ->calculatedValue !== null )) {
434
441
return $ this ->calculatedValue ; // Fallback for calculations referencing external files.
435
442
} elseif (preg_match ('/[Uu]ndefined (name|offset: 2|array key 2)/ ' , $ ex ->getMessage ()) === 1 ) {
@@ -441,6 +448,7 @@ public function getCalculatedValue(bool $asArray = false, bool $resetLog = true)
441
448
);
442
449
}
443
450
451
+ SharedDate::setExcelCalendar ($ currentCalendar );
444
452
if ($ result === '#Not Yet Implemented ' ) {
445
453
return $ this ->calculatedValue ; // Fallback if calculation engine does not support the formula.
446
454
}
0 commit comments