MNB PHPExcelDeveloper Guide

Formulas examples

Formulas Excel examples, explained clearly.

Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.

6examples in this category
21supported categories
5implementation paths
Monolithic library

Formulas examples with copy-ready, production-minded PHP.

Each example identifies the exact methods it uses and can be opened independently from the right-side index.

6
examples
3
documented methods
Example 01

SUM

MnbExcel::formula()currencyColumns()
sum.php
<?php

declare(strict_types=1);

/*
Summary:
    Write a SUM formula as a typed cell value. A cached result keeps previews useful before Excel
    recalculates.

Implementation note:
    Formula strings may include or omit the leading equals sign.
*/

use Mnb\PHPExcel\MnbExcel;

$rows = [
    ['Month' => 'January', 'Sales' => 1_200],
    ['Month' => 'February', 'Sales' => 1_650],
    ['Month' => 'March', 'Sales' => 2_050],
    ['Month' => 'Total', 'Sales' => MnbExcel::formula('SUM(B2:B4)', 4_900)],
];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->currencyColumns(['Sales'], '$')
    ->save('sum.xlsx');