Skip to content
MNB PHPExcelDeveloper Guide
AI

Reading workbooks

Formulas, Calculated Values, and Dates

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

Level
Intermediate
Reading time
11 min
Package
mnb/mnb-phpexcel
Updated
withFormulaMode()calculatedCell()calculatedRange()cellDetails()

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#