Reading Native XLS Files
Read BIFF8 worksheets, Unicode shared strings, dates, formulas, cached values, and projected rows with the native reader.
Updated
Xls::read()XlsReader::readSheet()XlsReader::sheetNames()ReadSession::rows()What you will learn
- Select a sheet by name or one-based index.
- Choose formula, cached-value, or combined formula results.
- Apply binary-parser safety limits to untrusted uploads.
Read associative rows#
use Mnb\PHPExcel\Format\Xls;
foreach (Xls::read('customers.xls')
->sheet('Customers')
->withHeaderRow()
->rows([
'skip_empty_rows' => true,
'max_rows' => 5000,
]) as $row) {
echo $row['Name'] . PHP_EOL;
}Choose a formula result mode#
$session = Xls::read('calculations.xls')->sheet('Summary');
$formulas = $session->toArray(['formula_cells' => 'formula']);
$cached = $session->toArray(['formula_cells' => 'cached_value']);
$both = $session->toArray(['formula_cells' => 'both']);both returns Mnb\PHPExcel\Reader\State\FormulaResult values containing the formula, cached result, result type, and native BIFF token metadata. Unknown BIFF tokens retain a diagnostic formula representation while their cached values remain readable.
Use direct reader operations when needed#
use Mnb\PHPExcel\Reader\XlsReader;
$reader = new XlsReader();
$sheetNames = $reader->sheetNames('report.xls');
$rows = $reader->readSheet('report.xls', 1, [
'start_row' => 2,
'end_row' => 1000,
'only_columns' => ['A', 'C', 'F'],
]);Limit binary parsing for uploads#
$rows = Xls::read('upload.xls')->toArray([
'max_file_size' => 64 * 1024 * 1024,
'max_stream_size' => 32 * 1024 * 1024,
'max_chain_sectors' => 200000,
'max_biff_records' => 1000000,
'max_shared_strings' => 250000,
]);Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue