MNB PHPExcelDeveloper Guide
v2.0.5
CSV module

CSV Module

Stream CSV and TSV data with dialect presets, delimiter detection, encoding conversion, projection, and safe output.

Updated

LevelAll levelsReading time6 minPackagemnb/mnb-phpexcel
Csv::read()Csv::write()CsvDialect::detectDelimiter()EncodingDetector::detectFile()

What you will learn

  • Install the single-sheet text format module.
  • Read large delimited files row by row.
  • Write Excel-friendly output while preventing formula injection.

Install the CSV package#

Terminal
composer require mnb/mnb-phpexcel:^2.0

Understand the format model#

CharacteristicCSV behavior
WorksheetsOne logical sheet named Sheet1.
TypesText fields; applications decide numeric, date, and boolean conversion.
StreamingForward-only fgetcsv() row iteration.
DialectExcel, Excel-tab, semicolon, Unix, pipe, or custom controls.
EncodingAutomatic detection and conversion to a requested target encoding.

Start with focused read and write APIs#

read-customers.php
use Mnb\PHPExcel\Format\Csv;

$rows = Csv::read('customers.csv', [
    'delimiter' => 'auto',
    'encoding' => 'auto',
    'trim_values' => true,
])->withHeaderRow(1)->rows();