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
01LEFT, RIGHT, MIDExtract fixed portions of identifiers and codes with Excel text formulas.
MediumExcel formula+
Extract fixed portions of identifiers and codes with Excel text formulas.
MnbExcel::formula()<?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');02CONCAT / TEXTJOINCombine cell values with or without a delimiter.
MediumExcel formula+
Combine cell values with or without a delimiter.
MnbExcel::formula()<?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');03TRIMRemove leading, trailing, and repeated internal spaces from imported text.
EasyExcel formula+
Remove leading, trailing, and repeated internal spaces from imported text.
MnbExcel::formula()<?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');04SUBSTITUTE / REPLACEReplace matching text or replace characters at a known position.
MediumExcel formula+
Replace matching text or replace characters at a known position.
MnbExcel::formula()<?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');Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue