CSV


CSV, Comma-Separated Values, is a spreadsheet-like computer file with values separated by commas.

What is it ?

The CSV plugin aims at integrating the CSV reader and writer into the Pipeline stack.

Installation

composer require php-etl/csv-plugin

Usage

Building an extractor

To build an extractor, you need to specify the path of your file.

csv:
  extractor:
    file_path: 'input.csv'

Building a loader

To build a loader, you need to specify the path of your file.

csv:
  loader:
    file_path: 'output.csv'

Additional options

To build extractors or loaders, additional options exist and can be used :

  • delimiter : sets the field separator
  • enclosure : sets the text enclosure character
  • escape : sets the escape character
  • safe_mode : enable safe mode in the Pipeline
  • columns : specify the name of the columns to retrieve or write
csv:
  loader:
    file_path: 'output.csv'
    delimiter: '/'
    enclosure: '"'
    escape: '\\'
    safe_mode: true
    columns:
      - firstname
      - lastname

Advanced Usage

Splitting into several files

To limit the number of lines to be written to your csv file, you can specify the max_lines option.

csv:
  loader:
    file_path: 'input.csv'
    excel:
      # ...
      max_lines: 20

Warning : this option is only available for loaders

See more

If you want to see complete configurations, please go to the examples folder.