PHP code example of mnb / mnb-phpexcel-xls
1. Go to this page and download the library: Download mnb/mnb-phpexcel-xls library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mnb / mnb-phpexcel-xls example snippets
declare(strict_types=1);
rows = Xls::read(__DIR__ . '/files/report.xls')
->sheet('Data')
->withHeaderRow()
->toArray([
'skip_empty_rows' => true,
'max_rows' => 5000,
]);
foreach ($rows as $row) {
echo $row['Name'] . PHP_EOL;
}
use Mnb\PHPExcel\Reader\XlsReader;
$reader = new XlsReader();
$sheetNames = $reader->sheetNames('report.xls');
$rows = $reader->readSheet('report.xls', 1);
use Mnb\PHPExcel\Core\CellValue;
use Mnb\PHPExcel\Format\Xls;
Xls::write([
['Name' => 'Alice', 'Amount' => 1250.50, 'Approved' => true],
['Name' => 'Bob', 'Amount' => 875.00, 'Approved' => false],
], __DIR__ . '/files/report.xls', [
'with_header' => true,
'sheet_name' => 'Data',
]);
Xls::write([
['Date', 'Amount', 'Double'],
[
CellValue::date('2026-07-29'),
CellValue::number('1250.50'),
CellValue::formula('B2*2', 2501.00),
],
], 'typed.xls');
$session = Xls::read('report.xls');
$formulas = $session->toArray(['formula_cells' => 'formula']);
$cached = $session->toArray(['formula_cells' => 'cached_value']);
$both = $session->toArray(['formula_cells' => 'both']);
Xls::write($workbook, 'report.xls', [
'strict_features' => true,
]);
$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,
]);
bash
php -d assert.exception=1 tests/run-native-smoke.php