MNB PHPExcelDeveloper Guide
v2.0.5
Reading workbooks

Formulas, Calculated Values, and Dates

Choose formula representations, calculate supported formulas, and normalize Excel date cells.

Updated

LevelIntermediateReading time11 minPackagemnb/mnb-phpexcel
withFormulaMode()calculatedCell()calculatedRange()cellDetails()

What you will learn

  • Distinguish formula expressions from cached and calculated values.
  • Read common business formulas through the native evaluator.
  • Handle Excel date systems without treating identifiers as dates.

Choose a formula mode#

PHP
use Mnb\PHPExcel\Reader\Options\ReaderOptions;

$options = ReaderOptions::defaults()->withFormulaMode('both');
$sheet = MnbExcel::read('finance.xlsx', $options)->sheet('Summary');
ModeUse
cachedUse the value saved by Excel or another producer.
formulaReturn the formula expression.
bothKeep the expression and cached result together.

Calculate a cell when current inputs matter#

PHP
$sheet = MnbExcel::read('finance.xlsx')->sheet('Summary');

$value = $sheet->calculatedCell('D12');
$totals = $sheet->calculatedRange('D2:D20');

Treat date conversion as a schema decision#

Excel stores dates as numbers plus a number format. The reader recognizes the 1900 and 1904 systems. In an import pipeline, normalize date values to DateTimeImmutable or an ISO string only for fields the schema defines as dates.

Do not calculate untrusted workbooks blindly#