Skip to content
MNB PHPExcelDeveloper Guide
AI

Structured output examples

Structured output Excel examples, explained clearly.

Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.

Monolithic library

Structured output examples with copy-ready, production-minded PHP.

Each example identifies the exact methods it uses and can be opened independently from the right-side index.

6
examples
10
documented methods
Example 01

Convert a workbook with toStructuredArray()

MnbExcel::read()toStructuredArray()toStructuredWorkbookArray()
convert-a-workbook-with-tostructuredarray.php
<?php

declare(strict_types=1);

/*
Summary:
    Return workbook-level source information, every sheet, normalized columns, rows, summaries,
    warnings, and errors in one PHP array.

Implementation note:
    toStructuredArray() returns workbook scope by default. It is designed for APIs, import previews,
    diagnostics, and audit-friendly processing rather than simple row-only imports.
*/

use Mnb\PHPExcel\MnbExcel;

$workbookPath = __DIR__ . '/fixtures/contacts.xlsx';

if (!is_file($workbookPath)) {
    throw new RuntimeException(sprintf('Workbook not found: %s', $workbookPath));
}

$structured = MnbExcel::read($workbookPath)
    ->toStructuredArray([
        'header_row' => true,
        'skip_empty_rows' => true,
        'header_case' => 'snake',
        'rename_headers' => [
            'e_mail' => 'email',
        ],
    ]);

print_r($structured['source']);
print_r($structured['summary']);
print_r($structured['sheets'][0]['rows'] ?? []);
Example 02

Return selected-sheet structured output

Example 03

Create flat structured rows

Example 04

Return structured JSON from an API

Example 05

Return structured XML from an API

Example 06

Explain total, empty, skipped, and returned row counts