MNB PHPExcelDeveloper Guide
v2.0.5

Text examples

Text 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.

4examples in this category
21focused categories
5implementation paths
01
LEFT, RIGHT, MID

Extract fixed portions of identifiers and codes with Excel text formulas.

MediumExcel formula
MnbExcel::formula()
left-right-mid.php
<?php

use Mnb\PHPExcel\MnbExcel;

$rows = [[
    'Code' => 'INV-2026-0042',
    'Prefix' => MnbExcel::formula('LEFT(A2,3)', 'INV'),
    'Number' => MnbExcel::formula('RIGHT(A2,4)', '0042'),
    'Year' => MnbExcel::formula('MID(A2,5,4)', '2026'),
]];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->save('text-parts.xlsx');
02
CONCAT / TEXTJOIN

Combine cell values with or without a delimiter.

MediumExcel formula
MnbExcel::formula()
concat-textjoin.php
<?php

use Mnb\PHPExcel\MnbExcel;

$rows = [[
    'First name' => 'Ava',
    'Last name' => 'Patel',
    'Full name' => MnbExcel::formula('CONCAT(A2," ",B2)', 'Ava Patel'),
    'CSV label' => MnbExcel::formula('TEXTJOIN(", ",TRUE,A2:B2)', 'Ava, Patel'),
]];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->save('concat-textjoin.xlsx');
03
TRIM

Remove leading, trailing, and repeated internal spaces from imported text.

EasyExcel formula
MnbExcel::formula()
trim.php
<?php

use Mnb\PHPExcel\MnbExcel;

$rows = [[
    'Raw name' => '  Ava   Patel  ',
    'Clean name' => MnbExcel::formula('TRIM(A2)', 'Ava Patel'),
]];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->save('trim.xlsx');
04
SUBSTITUTE / REPLACE

Replace matching text or replace characters at a known position.

MediumExcel formula
MnbExcel::formula()
substitute-replace.php
<?php

use Mnb\PHPExcel\MnbExcel;

$rows = [[
    'Phone' => '555-010-2026',
    'Digits' => MnbExcel::formula('SUBSTITUTE(A2,"-","")', '5550102026'),
    'Masked' => MnbExcel::formula('REPLACE(A2,1,7,"***-***")', '***-***-2026'),
]];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->save('substitute-replace.xlsx');