MNB PHPExcelDeveloper Guide
v2.0.5
Reading workbooks

Cells, Ranges, and Projection

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

Updated

LevelIntermediateReading time10 minPackagemnb/mnb-phpexcel
cell()cells()cellDetails()rangeValues()rangeStyles()projectColumns()

What you will learn

  • Use cell access for lookup-style workbooks.
  • Use ranges for compact rectangular data.
  • Project columns before normalization to reduce work.

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();