Skip to content
MNB PHPExcelDeveloper Guide
AI

Reading workbooks

Cells, Ranges, and Projection

Read individual values, typed metadata snapshots, rectangular ranges, and selected columns.

Level
Intermediate
Reading time
10 min
Package
mnb/mnb-phpexcel
Updated
Full packageIndividual XLSXDirect cells
cell()cells()cellDetails()rangeValues()rangeStyles()projectColumns()

Read one or several cells#

PHP
$sheet = MnbExcel::read('finance.xlsx')->sheet('Summary');

$total = $sheet->cell('D12');
$values = $sheet->cells(['B2', 'D12', 'F20']);

Read a complete cell snapshot#

PHP
$cell = MnbExcel::read('finance.xlsx')
    ->sheet('Summary')
    ->cellDetails('D12');

printf("Coordinate: %s\n", $cell->coordinate);
printf("Formula: %s\n", $cell->formula ?? 'none');
print_r($cell->style);

A snapshot may include formula information, number format, style, hyperlink, comment, protection, rich text, and merged-range membership.

Read a rectangular range#

PHP
$matrix = MnbExcel::read('finance.xlsx')
    ->sheet('Summary')
    ->rangeValues('A1:F20');

Project only required columns#

PHP
$rows = MnbExcel::read('orders.xlsx')
    ->sheet('Orders')
    ->withHeaderRow(1)
    ->projectColumns(['Order ID', 'Customer', 'Amount'])
    ->streaming()
    ->rows();