Formulas, Calculated Values, and Dates
Choose formula representations, calculate supported formulas, and normalize Excel date cells.
Updated
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#
use Mnb\PHPExcel\Reader\Options\ReaderOptions;
$options = ReaderOptions::defaults()->withFormulaMode('both');
$sheet = MnbExcel::read('finance.xlsx', $options)->sheet('Summary');| Mode | Use |
|---|---|
cached | Use the value saved by Excel or another producer. |
formula | Return the formula expression. |
both | Keep the expression and cached result together. |
Calculate a cell when current inputs matter#
$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#
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue