MNB PHPExcelDeveloper Guide
v2.0.5
Core concepts

Cell Values and PHP Types

Write intentional text, numbers, booleans, dates, formulas, and blanks without losing meaning.

Updated

LevelIntermediateReading time8 minPackagemnb/mnb-phpexcel
MnbExcel::text()number()bool()date()formula()blank()

What you will learn

  • Prevent identifiers with leading zeroes from becoming numbers.
  • Write dates and formulas deliberately.
  • Understand the difference between a value and its display format.

Use typed cell values when inference is ambiguous#

PHP
use Mnb\PHPExcel\MnbExcel;

$row = [
    'Postal Code' => MnbExcel::text('00123'),
    'Quantity' => MnbExcel::number(12),
    'Active' => MnbExcel::bool(true),
    'Joined At' => MnbExcel::date(new DateTimeImmutable('2026-07-26')),
    'Total' => MnbExcel::formula('=B2*C2', 249.95),
    'Notes' => MnbExcel::blank(),
];

Separate stored values from display formats#

A numeric amount should remain numeric. Apply a currency number format to control how Excel displays it. The same principle applies to dates, percentages, decimals, and identifiers.

PHP
MnbExcel::report($rows)
    ->currencyColumns(['Amount'], '$')
    ->percentageColumns(['Completion'])
    ->dateStyleColumns(['Order Date'], 'yyyy-mm-dd')
    ->save('report.xlsx');

Protect untrusted text from formula injection#

PHP
MnbExcel::fromArray($rows)
    ->escapeFormulaLikeText()
    ->save('safe-export.xlsx');