Skip to content
MNB PHPExcelDeveloper Guide
AI

XLS library

Writing Native XLS Files

Generate BIFF8 workbooks natively with multiple sheets, Unicode strings, typed cells, formulas, merges, dimensions, and frozen panes.

Level
Intermediate
Reading time
11 min
Package
mnb/mnb-phpexcel-xls
Updated
Xls::write()XlsWriter::write()CellValue::formula()

Write associative rows#

PHP
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#

PHP
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#

PHP
Xls::write($workbook, 'report.xls', [
    'strict_features' => true,
]);

With strict mode enabled, unsupported workbook presentation features raise UnsupportedXlsFeatureException instead of being skipped.