PHPackages                             mnb/mnb-phpexcel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. mnb/mnb-phpexcel

ActiveLibrary[File &amp; Storage](/categories/file-storage)

mnb/mnb-phpexcel
================

Array-first PHP Excel engine for small and normal XLSX, CSV, JSON, XML, SQL, reports, validation, import quality, and cell safety workflows.

1.0.0(yesterday)03↑2900%MITPHPPHP &gt;=8.1

Since Jul 1Pushed todayCompare

[ Source](https://github.com/mnagendrababu23/mnb-phpexcel)[ Packagist](https://packagist.org/packages/mnb/mnb-phpexcel)[ RSS](/packages/mnb-mnb-phpexcel/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

MNB PHPExcel
============

[](#mnb-phpexcel)

**MNB PHPExcel** is an **array-first PHP Excel engine** for small and normal XLSX/CSV/JSON/XML workflows.

```
PHP Array ⇄ XLSX ⇄ CSV ⇄ JSON ⇄ XML ⇄ SQL

```

Current public release:

```
v1.0.0 — First Public Release

```

This release intentionally focuses on **small-file PHPExcel-style functionality**. Large-file streaming, chunk workers, NDJSON staging, and parallel imports are planned for a future engine layer and are not part of this first public release.

Install
-------

[](#install)

```
composer require mnb/mnb-phpexcel
```

Required for XLSX read/write:

```
ext-zip
ext-xmlreader

```

Required for core package features:

```
PHP >= 8.1
ext-json
ext-pdo

```

Recommended for better legacy CSV encoding support:

```
ext-mbstring
ext-iconv

```

Main idea
---------

[](#main-idea)

Most PHP applications already use arrays from database queries, APIs, forms, and admin panels. MNB PHPExcel makes those arrays easy to export, import, validate, inspect, and convert.

```
use Mnb\PHPExcel\MnbExcel;

MnbExcel::fromArray($rows)->save('students.xlsx');
$rows = MnbExcel::read('students.xlsx')->toArray();
```

Core features
-------------

[](#core-features)

### Array-first API

[](#array-first-api)

- `MnbExcel::fromArray()`
- `MnbExcel::fromWorkbookArray()`
- `MnbExcel::read()`
- `MnbExcel::readCsv()`
- `MnbExcel::fromJson()`
- `MnbExcel::readJson()`
- `MnbExcel::fromSql()`
- `toArray()`
- `toStructuredArray()`
- `toStructuredJson()` / `saveStructuredJson()`
- `importToSql()`
- `toJson()` / `saveJson()`
- `toXml()` / `saveXml()`

### XLSX support

[](#xlsx-support)

- Create XLSX files from arrays.
- Read XLSX files into arrays.
- Multiple worksheets.
- Sheet selection by index or name.
- Sheet name listing.
- Relationship-based sheet lookup using `workbook.xml.rels`.
- Shared strings and inline strings.
- Number, text, boolean, blank, error, date, and formula cells.
- Date style detection.
- Excel 1900 and 1904 date systems.
- Hidden sheet/row/column inspection.
- Hidden row and hidden column skip options.
- Corrupted XLSX structure checks.
- Formula cached value or formula text read mode.

### CSV support

[](#csv-support)

- CSV read/write.
- Dialect presets: `excel`, `semicolon`, `excel_tab`, `unix`, `pipe`.
- Custom delimiter, enclosure, escape, and line ending.
- UTF-8 BOM option.
- Advanced encoding auto-detection.
- UTF-8, UTF-8 BOM, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE, Windows-1252, and ISO-8859-1 support.
- Locale-aware number parsing.
- Locale-aware date parsing.
- CSV injection policy modes: `escape`, `tab_escape`, `strip`, `block`, `none`.

### JSON and XML conversion

[](#json-and-xml-conversion)

- Convert XLSX/CSV selected sheet rows to JSON.
- Convert XLSX/CSV selected sheet rows to XML.
- Convert JSON files to XLSX/CSV/XML/SQL through the array-first engine.
- Export array workbooks directly as JSON or XML.
- Supports associative rows as object/XML field nodes.
- Supports list rows as array/cell nodes.
- Safe XML tag-name normalization.
- XML escaping for special characters such as `&`, ``, quotes, and apostrophes.
- JSON options for pretty output, Unicode preservation, slash preservation, and zero-fraction preservation.
- JSON import supports list-of-objects, single object, `{"rows": [...]}`, sheet maps, and `{"sheets": ...}` workbook formats.
- Nested JSON objects can be flattened into columns such as `address.city`.
- Large JSON integers are decoded as strings to avoid precision loss.

### JSON to Excel

[](#json-to-excel)

Simple list-of-objects JSON:

```
[
  {"student_id":"000123", "name":"Ravi", "address":{"city":"Hyderabad"}},
  {"student_id":"000124", "name":"Sita", "address":{"city":"Vijayawada"}}
]
```

Convert JSON to XLSX:

```
MnbExcel::fromJson('students.json')
    ->textColumns(['student_id'])
    ->autoWidth()
    ->freezeHeader()
    ->autoFilter()
    ->save('students.xlsx');
```

Workbook-style JSON becomes multiple sheets:

```
{
  "Students": [
    {"name":"Ravi", "email":"ravi@example.com"}
  ],
  "Teachers": [
    {"name":"Kumar", "subject":"Maths"}
  ]
}
```

```
MnbExcel::fromJson('school.json')
    ->save('school.xlsx');
```

Read JSON to array:

```
$rows = MnbExcel::readJson('students.json')
    ->toArray(['header_row' => true]);
```

JSON to CSV/XML:

```
MnbExcel::fromJson('students.json')->save('students.csv');
MnbExcel::fromJson('students.json')->saveXml('students.xml', [
    'root' => 'students',
    'row' => 'student',
]);
```

### Improved workbook output structure

[](#improved-workbook-output-structure)

For normal imports, `toArray()` returns only row data. For API/debug/import workflows, use `toStructuredArray()` to get workbook-level output with all sheets.

```
$structured = MnbExcel::read('Heilberufe.xlsx')
    ->toStructuredArray([
        'header_row' => true,
        'skip_empty_rows' => true,
        'include_hidden_rows' => false,
        'include_hidden_columns' => false,
        'rename_headers' => [
            'affilication' => 'affiliation',
        ],
    ]);
```

Workbook output shape:

```
[
    'status' => 'ok',
    'source' => [
        'file' => 'Heilberufe.xlsx',
        'format' => 'xlsx',
        'size_bytes' => 9150,
    ],
    'sheets' => [
        0 => [
            'index' => 1,
            'sheetname' => 'Worksheet',
            'name' => 'Worksheet',
            'state' => 'visible',
            'dimension' => 'A1:F27',
            'headers' => ['author_name', 'email', 'title', 'affiliation', 'article_type', 'link'],
            'columns' => [
                [
                    'index' => 1,
                    'letter' => 'A',
                    'header' => 'author_name',
                    'original_header' => 'author_name',
                    'key' => 'author_name',
                    'renamed' => false,
                ],
            ],
            'rows' => [
                [
                    'index' => 0,
                    'row_number' => 2,
                    'values' => [
                        'author_name' => 'Peter Heinz',
                        'email' => 'heinz@augeninfo.de',
                    ],
                ],
            ],
            'summary' => [
                'source_rows' => 27,
                'processed_rows' => 27,
                'data_rows' => 26,
                'columns' => 6,
                'header_row_number' => 1,
            ],
            'warnings' => [],
            'errors' => [],
        ],
    ],
    'summary' => [
        'sheet_count' => 1,
        'source_rows' => 27,
        'processed_rows' => 27,
        'data_rows' => 26,
        'columns_total' => 6,
        'skipped_empty_rows' => 0,
    ],
    'warnings' => [],
    'errors' => [],
]
```

For selected-sheet-only structure, use `toStructuredSheetArray()` or pass `['structure' => 'sheet']` to `toStructuredArray()`.

```
$sheetOnly = MnbExcel::read('Heilberufe.xlsx')
    ->sheet('Worksheet')
    ->toStructuredSheetArray([
        'header_row' => true,
    ]);
```

Save workbook structured output directly as JSON:

```
MnbExcel::read('Heilberufe.xlsx')
    ->saveStructuredJson('heilberufe-structured.json', [
        'header_row' => true,
        'rename_headers' => ['affilication' => 'affiliation'],
    ]);
```

Header options:

```
'header_case' => 'snake',      // default: Author Name -> author_name
'header_case' => 'preserve',   // keep original header text
'header_case' => 'camel',      // Author Name -> authorName
'rename_headers' => [
    'affilication' => 'affiliation',
]
```

### Report builder

[](#report-builder)

- `MnbExcel::report()`.
- Title rows.
- Subtitle/custom title rows.
- Summary rows.
- Footer rows.
- Built-in templates: `simple`, `business`, `finance`.
- Named styles.
- Header styling.
- Column, row, cell, and range styles.
- Currency, percentage, date, datetime, integer, decimal, and text formats.
- Auto-width estimation.
- Freeze panes.
- Auto filter.
- Conditional row styling.
- Workbook metadata.
- Safe file and sheet names.

### Import quality tools

[](#import-quality-tools)

- Import preview.
- Required column detection.
- Unexpected column detection.
- Strict column mode.
- Column mapping suggestions.
- Duplicate row detection.
- Original row number preservation.
- Failed rows report.
- Import summary workbook/sheet.
- SQL dry-run before insert.

### Validation

[](#validation)

Supported rules:

```
required
nullable
required_if
email
url
numeric
integer
string
boolean
date
alpha
alpha_num
phone_basic
min
max
length
in
regex
starts_with
ends_with
unique_in_file

```

Validation results include simple error messages and detailed metadata:

```
[
    'row' => 7,
    'column' => 'email',
    'value' => 'wrong-email',
    'rule' => 'email',
    'message' => 'email must be a valid email.',
]
```

### Formula and cell safety

[](#formula-and-cell-safety)

- Explicit typed cell helpers:
    - `MnbExcel::text()`
    - `MnbExcel::number()`
    - `MnbExcel::bool()`
    - `MnbExcel::date()`
    - `MnbExcel::formula()`
    - `MnbExcel::blank()`
- Formula policies:
    - `safe`
    - `block`
    - `allow`
- Dangerous formula detection for external links, URLs, and risky functions.
- Formula-like text escaping by default.
- Excel 32,767-character cell limit protection.
- Invalid XML/control character handling.
- Long numeric text detection to avoid precision loss.
- Cell safety scanner.

Examples
--------

[](#examples)

### Array to XLSX

[](#array-to-xlsx)

```
use Mnb\PHPExcel\MnbExcel;

$rows = [
    ['name' => 'Ravi', 'email' => 'ravi@example.com', 'phone' => '0987654321'],
    ['name' => 'Sita', 'email' => 'sita@example.com', 'phone' => '0912345678'],
];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->textColumns(['phone'])
    ->autoWidth()
    ->freezeHeader()
    ->autoFilter()
    ->save('students.xlsx');
```

### XLSX to array

[](#xlsx-to-array)

```
$rows = MnbExcel::read('students.xlsx')
    ->sheet('Students')
    ->toArray([
        'header_row' => true,
        'skip_empty_rows' => true,
        'preserve_original_row_numbers' => true,
        'include_hidden_rows' => false,
        'include_hidden_columns' => false,
    ]);
```

### CSV with encoding auto-detection

[](#csv-with-encoding-auto-detection)

```
$rows = MnbExcel::readCsv('legacy-users.csv', [
    'encoding' => 'auto',
    'trim_values' => true,
])->toArray([
    'header_row' => true,
]);
```

### Excel to JSON

[](#excel-to-json)

```
MnbExcel::read('students.xlsx')
    ->sheet('Students')
    ->saveJson('students.json', [
        'header_row' => true,
        'skip_empty_rows' => true,
    ]);
```

Array-first JSON export:

```
MnbExcel::fromArray($rows)
    ->withHeader()
    ->saveJson('students.json', ['mode' => 'rows']);
```

### Excel to XML

[](#excel-to-xml)

```
MnbExcel::read('students.xlsx')
    ->sheet('Students')
    ->saveXml('students.xml', [
        'header_row' => true,
        'skip_empty_rows' => true,
    ], [
        'root' => 'students',
        'row' => 'student',
    ]);
```

Array-first XML export:

```
MnbExcel::fromArray($rows)
    ->withHeader()
    ->saveXml('students.xml', [
        'root' => 'students',
        'row' => 'student',
    ]);
```

### JSON to Excel

[](#json-to-excel-1)

Simple list-of-objects JSON:

```
[
  {"student_id":"000123", "name":"Ravi", "address":{"city":"Hyderabad"}},
  {"student_id":"000124", "name":"Sita", "address":{"city":"Vijayawada"}}
]
```

Convert JSON to XLSX:

```
MnbExcel::fromJson('students.json')
    ->textColumns(['student_id'])
    ->autoWidth()
    ->freezeHeader()
    ->autoFilter()
    ->save('students.xlsx');
```

Workbook-style JSON becomes multiple sheets:

```
{
  "Students": [
    {"name":"Ravi", "email":"ravi@example.com"}
  ],
  "Teachers": [
    {"name":"Kumar", "subject":"Maths"}
  ]
}
```

```
MnbExcel::fromJson('school.json')
    ->save('school.xlsx');
```

Read JSON to array:

```
$rows = MnbExcel::readJson('students.json')
    ->toArray(['header_row' => true]);
```

JSON to CSV/XML:

```
MnbExcel::fromJson('students.json')->save('students.csv');
MnbExcel::fromJson('students.json')->saveXml('students.xml', [
    'root' => 'students',
    'row' => 'student',
]);
```

### Report builder

[](#report-builder-1)

```
MnbExcel::report($rows, 'business')
    ->title('Student Export Report')
    ->columns([
        'name' => 'Student Name',
        'email' => 'Email Address',
        'marks' => 'Marks',
        'status' => 'Status',
        'amount' => 'Amount',
    ])
    ->integerColumns(['marks'])
    ->currencyColumns(['amount'], '₹')
    ->conditionalRowStyle(
        static fn (array $row): bool => ($row['status'] ?? '') === 'fail',
        'mnb.row.danger'
    )
    ->metadata(['creator' => 'MNB PHPExcel'])
    ->autoWidth()
    ->save('student-report.xlsx');
```

### Validation and failed rows report

[](#validation-and-failed-rows-report)

```
$result = MnbExcel::validateImport($rows, [
    'name' => 'required|alpha|max:100',
    'email' => 'required|email|unique_in_file',
    'phone' => 'required|phone_basic',
    'website' => 'nullable|url',
], [
    'row_number_key' => '_mnb_original_row_number',
]);

MnbExcel::fromFailedRows($result['failed'])
    ->withImportSummarySheet(['total_rows' => count($rows)], $result)
    ->save('failed-rows.xlsx');
```

### SQL dry-run

[](#sql-dry-run)

```
$plan = MnbExcel::read('students.xlsx')
    ->sheet('Students')
    ->dryRunImportToSql($pdo, 'students', [
        'header_row' => true,
        'batch_size' => 500,
    ]);
```

### Release readiness check

[](#release-readiness-check)

```
$report = MnbExcel::releaseReadiness(__DIR__);
```

Local testing
-------------

[](#local-testing)

Run syntax checks:

```
composer run test:syntax
```

Run smoke tests:

```
composer run test:smoke
```

Run all configured tests:

```
composer test
```

In this environment, XLSX runtime tests require `ext-zip` and `ext-xmlreader`. If they are missing, the XLSX smoke test exits safely with a skip message.

Public release checklist
------------------------

[](#public-release-checklist)

Before Packagist release:

```
git add .
git commit -m "Release MNB PHPExcel v1.0.0"
git tag v1.0.0
git push origin main
git push origin v1.0.0
```

Do not include:

```
vendor/
storage/
.tmp/
.cache/
generated XLSX/CSV outputs

```

Scope note
----------

[](#scope-note)

MNB PHPExcel v1.0.0 is for **small and normal Excel files**. It is designed to be complete and accurate for the supported non-large-file feature set. Large-file streaming support will be designed separately later.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/86346429?v=4)[Nagendra Babu Macharla](/maintainers/mnagendrababu23)[@mnagendrababu23](https://github.com/mnagendrababu23)

---

Top Contributors

[![mnagendrababu23](https://avatars.githubusercontent.com/u/86346429?v=4)](https://github.com/mnagendrababu23 "mnagendrababu23 (4 commits)")

### Embed Badge

![Health badge](/badges/mnb-mnb-phpexcel/health.svg)

```
[![Health](https://phpackages.com/badges/mnb-mnb-phpexcel/health.svg)](https://phpackages.com/packages/mnb-mnb-phpexcel)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
