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,
]);
$report = Xls::metaInfo('report.xls', [
'profile' => 'full',
'max_items' => 1000,
]);
$report = Xls::read('report.xls')->metaInfo([
'profile' => 'forensic',
'
Xls::updateMetaInfo('source.xls', 'updated.xls', [
'document' => [
'title' => 'Annual Report',
'creator' => 'MNB',
'category' => 'Finance',
],
'revision' => [
'last_saved_by' => 'Release Bot',
'revision_number' => '7',
'total_editing_time_seconds' => 3600,
],
'application' => [
'application_name' => 'MNB PHPExcel',
'application_version' => '2.0',
'manager' => 'Finance Manager',
'company' => 'MNB',
],
'custom_properties' => [
'Project ID' => 'PRJ-1001',
'Approved' => ['type' => 'boolean', 'value' => true],
'Budget' => ['type' => 'float', 'value' => 1250.50],
'Revision Date' => ['type' => 'datetime', 'value' => '2026-08-02T10:00:00Z'],
],
'workbook' => [
'active_sheet' => 'Summary',
'sheet_visibility' => ['Raw Data' => 'hidden'],
'date1904' => false,
],
'calculation' => [
'mode' => 'automatic',
'iterate' => false,
'iterate_count' => 100,
'iterate_delta' => 0.001,
'calc_on_save' => true,
'reference_mode' => 'a1',
],
]);
Xls::removePersonalInfo('source.xls', 'clean.xls', [
'remove_custom_properties' => true,
'remove_descriptive_properties' => false,
]);
bash
php -d assert.exception=1 tests/run-native-smoke.php