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
21supported categories
5implementation paths
Monolithic library
Text 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.
- 4
- examples
- 1
- documented methods
MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Extract fixed portions of identifiers and codes with Excel text formulas.
Implementation note:
Store extracted numeric-looking identifiers as text when leading zeroes matter.
*/
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');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Combine cell values with or without a delimiter.
Implementation note:
TEXTJOIN is convenient when blank values should be ignored.
*/
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');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Remove leading, trailing, and repeated internal spaces from imported text.
Implementation note:
For server-side imports, also normalize whitespace in PHP before database validation.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Raw name' => ' Ava Patel ',
'Clean name' => MnbExcel::formula('TRIM(A2)', 'Ava Patel'),
]];
MnbExcel::fromArray($rows)
->withHeader()
->save('trim.xlsx');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Replace matching text or replace characters at a known position.
Implementation note:
SUBSTITUTE matches text values; REPLACE works by position and character count.
*/
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');No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue