MNB PHPExcelDeveloper Guide
v2.0.5
CSV module

Writing CSV and TSV Files

Generate atomic, Excel-friendly delimited files with BOM, encoding, dialect, and injection controls.

Updated

LevelIntermediateReading time7 minPackagemnb/mnb-phpexcel
Csv::write()CsvDialect::resolve()

What you will learn

  • Choose an output dialect for Excel, Unix, tab, semicolon, or pipe consumers.
  • Write UTF-8 or another supported encoding with an appropriate BOM.
  • Protect spreadsheet consumers from formula-like text.

Write an Excel-friendly CSV#

PHP
Csv::write($rows, 'report.csv', [
    'with_header' => true,
    'dialect' => 'excel',
    'encoding' => 'UTF-8',
    'bom' => true,
    'injection_policy' => 'escape',
]);

Choose a dialect preset#

PresetDelimiterLine endingBOM
excelCommaCRLFYes
excel_tabTabCRLFYes
semicolonSemicolonCRLFYes
unixCommaLFNo
pipePipeLFNo

Prevent formula injection#