PHPackages                             atk14/csv-writer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. atk14/csv-writer

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

atk14/csv-writer
================

Writes CSV into string output or a file. Also provides export to XLSX format.

v1.2.1(2y ago)017.7k↓37.1%2MITPHPPHP &gt;=5.4.0CI passing

Since Oct 10Pushed 1w ago2 watchersCompare

[ Source](https://github.com/atk14/CsvWriter)[ Packagist](https://packagist.org/packages/atk14/csv-writer)[ Docs](https://github.com/atk14/CsvWriter)[ RSS](/packages/atk14-csv-writer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (10)Used By (2)

CsvWriter
=========

[](#csvwriter)

[![Tests](https://github.com/atk14/CsvWriter/actions/workflows/tests.yml/badge.svg)](https://github.com/atk14/CsvWriter/actions/workflows/tests.yml)

Writes CSV into string output or a file. Also provides export to XLSX format.

Basic usage
-----------

[](#basic-usage)

```
$writer = new CsvWriter([
  "delimiter" => ";",
  "quote" => '"',
  "escape_char" => "\\",
]);

$writer->addRow([
  "product_no" => "CAN_G1X",
  "price" => 4999.0,
]);

$writer->addRow([
  "product_no" => "CAN_G15",
  "price" => 2099.99,
]);

echo $writer->writeToString();
//  CAN_G1X;4999
//  CAN_G15;2099.99

echo $writer->writeToString(["with_header" => true]);
//  product_no;price
//  CAN_G1X;4999
//  CAN_G15;2099.99

echo $writer->writeToString(["with_header" => ["Product No.","Price"]]);
//  "Product No.";Price
//  CAN_G1X;4999
//  CAN_G15;2099.99

```

The header can be added automatically with the "with\_header" option set to "auto":

```
$writer = new CsvWriter();
$writer->addRow(["k1" => "v1", "k2" => "v2"]);
echo $writer->writeToString(["with_header" => "auto"]);
// k1;k2
// v2;v2

$writer = new CsvWriter();
$writer->addRow(["v1","v2"]);
echo $writer->writeToString(["with_header" => "auto"]);
// v2;v2

```

CsvWriter implements ArrayAccess for easier rows adding:

```
$writer[] = ["k1" => "v1","k2" => "v2"];
$writer[] = ["k1" => "v3","k2" => "v4"];

```

### XLSX format

[](#xlsx-format)

```
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename=data.xlsx");
echo $writer->writeToString(["format" => "xlsx"]);

```

### Export to a file

[](#export-to-a-file)

```
$writer->writeToFile("/path/to/a/file.csv",["with_header" => true]);
$writer->writeToFile("/path/to/a/file.xlsx",["with_header" => true, "format" => "xlsx"]);

```

### Special options

[](#special-options)

In case of exporting to CSV, the BOM sequence is automatically written at the beginning of the file. It can be disabled by the options write\_bom set to false.

```
$write->writeToFile("/path/to/a/file.csv",[
  "format" => "csv",
  "write_bom" => false
]);

```

Sheet name can be set for XLSX export.

```
$write->writeToFile("/path/to/a/file.xlsx",[
  "format" => "xlsx",
  "sheet_name" => "Order history"
]);

```

Installation
------------

[](#installation)

```
composer require atk14/cvs-writer

```

Testing
-------

[](#testing)

```
composer update --dev
./vendor/bin/run_unit_tests test

```

License
-------

[](#license)

CsvWriter is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance64

Regular maintenance activity

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~165 days

Recently: every ~233 days

Total

8

Last Release

935d ago

PHP version history (2 changes)v1.0PHP &gt;=5.6.0

v1.0.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/974278?v=4)[Jaromir Tomek](/maintainers/yarri)[@yarri](https://github.com/yarri)

---

Top Contributors

[![yarri](https://avatars.githubusercontent.com/u/974278?v=4)](https://github.com/yarri "yarri (51 commits)")

---

Tags

exportxlsxlsxcsvexporterwriter

### Embed Badge

![Health badge](/badges/atk14-csv-writer/health.svg)

```
[![Health](https://phpackages.com/badges/atk14-csv-writer/health.svg)](https://phpackages.com/packages/atk14-csv-writer)
```

###  Alternatives

[sonata-project/exporter

Lightweight Exporter library

44921.6M40](/packages/sonata-project-exporter)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k27.0M52](/packages/rap2hpoutre-fast-excel)[kartik-v/yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)

1693.3M36](/packages/kartik-v-yii2-export)[nuovo/spreadsheet-reader

Spreadsheet reader library for Excel, OpenOffice and structured text files

671891.8k8](/packages/nuovo-spreadsheet-reader)[avadim/fast-excel-writer

Lightweight and very fast XLSX Excel Spreadsheet Writer in PHP

3051.4M11](/packages/avadim-fast-excel-writer)[avadim/fast-excel-reader

Lightweight and very fast XLSX Excel Spreadsheet and CSV Reader in PHP

107737.8k11](/packages/avadim-fast-excel-reader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
