@@ -176,16 +176,21 @@ public function getValue()
176176
177177 /**
178178 * Get cell value with formatting.
179- *
180- * @return string
181179 */
182- public function getFormattedValue ()
180+ public function getFormattedValue (): string
183181 {
184- return (string ) NumberFormat::toFormattedString (
182+ $ currentCalendar = SharedDate::getExcelCalendar ();
183+ SharedDate::setExcelCalendar ($ this ->getWorksheet ()->getParent ()->getExcelCalendar ());
184+
185+ $ formattedValue = (string ) NumberFormat::toFormattedString (
185186 $ this ->getCalculatedValue (),
186187 $ this ->getStyle ()
187188 ->getNumberFormat ()->getFormatCode ()
188189 );
190+
191+ SharedDate::setExcelCalendar ($ currentCalendar );
192+
193+ return $ formattedValue ;
189194 }
190195
191196 /**
@@ -342,8 +347,6 @@ public function setValueExplicit($value, $dataType, bool $isArrayFormula = false
342347 break ;
343348 default :
344349 throw new Exception ('Invalid datatype: ' . $ dataType );
345-
346- break ;
347350 }
348351
349352 // set the datatype
@@ -402,6 +405,9 @@ private function processArrayResult(
402405 public function getCalculatedValue (bool $ asArray = false , bool $ resetLog = true )
403406 {
404407 if ($ this ->dataType === DataType::TYPE_FORMULA ) {
408+ $ currentCalendar = SharedDate::getExcelCalendar ();
409+ SharedDate::setExcelCalendar ($ this ->getWorksheet ()->getParent ()->getExcelCalendar ());
410+
405411 try {
406412 $ coordinate = $ this ->getCoordinate ();
407413 $ worksheet = $ this ->getWorksheet ();
@@ -430,6 +436,7 @@ public function getCalculatedValue(bool $asArray = false, bool $resetLog = true)
430436 $ this ->getWorksheet ()->setSelectedCells ($ selected );
431437 $ this ->getWorksheet ()->getParent ()->setActiveSheetIndex ($ index );
432438 } catch (Exception $ ex ) {
439+ SharedDate::setExcelCalendar ($ currentCalendar );
433440 if (($ ex ->getMessage () === 'Unable to access External Workbook ' ) && ($ this ->calculatedValue !== null )) {
434441 return $ this ->calculatedValue ; // Fallback for calculations referencing external files.
435442 } 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)
441448 );
442449 }
443450
451+ SharedDate::setExcelCalendar ($ currentCalendar );
444452 if ($ result === '#Not Yet Implemented ' ) {
445453 return $ this ->calculatedValue ; // Fallback if calculation engine does not support the formula.
446454 }
0 commit comments