Writing Native XLS Files
Generate BIFF8 workbooks natively with multiple sheets, Unicode strings, typed cells, formulas, merges, dimensions, and frozen panes.
Updated
Xls::write()XlsWriter::write()CellValue::formula()What you will learn
- Write data-oriented Excel 97–2003 workbooks without external libraries.
- Provide typed dates, numbers, errors, and cached formula values.
- Fail explicitly when an unsupported presentation feature is required.
Write associative rows#
use Mnb\PHPExcel\Format\Xls;
Xls::write([
['Name' => 'Alice', 'Amount' => 1250.50, 'Approved' => true],
['Name' => 'Bob', 'Amount' => 875.00, 'Approved' => false],
], 'report.xls', [
'with_header' => true,
'sheet_name' => 'Data',
]);Write typed values and formulas#
use Mnb\PHPExcel\Core\CellValue;
use Mnb\PHPExcel\Format\Xls;
Xls::write([
['Date', 'Amount', 'Double'],
[
CellValue::date('2026-07-29'),
CellValue::number('1250.50'),
CellValue::formula('B2*2', 2501.00),
],
], 'typed.xls');Supported writer structure#
- Multiple worksheets and Unicode shared strings with CONTINUE splitting.
- Numbers, strings, Booleans, blanks, errors, dates, and date-times.
- Common formulas encoded as BIFF8 RPN tokens with cached results.
- Merged cells, row heights, column widths, and frozen rows or columns.
- Atomic output replacement and BIFF8 worksheet limits of 65,536 rows and 256 columns.
Require strict feature handling#
Xls::write($workbook, 'report.xls', [
'strict_features' => true,
]);With strict mode enabled, unsupported workbook presentation features raise UnsupportedXlsFeatureException instead of being skipped.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue