MNB PHPExcelDeveloper Guide

CSV · Basic

CSV basic examples.

Package-local, copy-ready examples organized like the classes and methods reference. Open one example at a time, search by method, and jump from the right-side index.

Packagemnb/mnb-phpexcel-csv:^2.0Reference1 examples · 1 methods
CSV individual library

Basic examples with copy-ready, production-minded PHP.

Every snippet uses mnb/mnb-phpexcel-csv or its declared Core dependency. Each copied snippet includes strict typing, a concise summary, implementation guidance, readable limits, and a safe fixture check.

1
examples
1
documented methods
Example 01

Write an Excel-friendly CSV

Open related guide
Csv::write()
write-an-excel-friendly-csv.php
<?php

declare(strict_types=1);

/*
Summary:
    Export rows with a header, UTF-8 BOM, Excel line endings, and atomic file replacement.

Implementation note:
    Keep formula-injection escaping enabled for untrusted values that may later be opened in
    spreadsheet software.
*/

use Mnb\PHPExcel\Format\Csv;

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