Next Previous Up Contents
Next: Tab-Separated Table
Up: Supplied Output Handlers
Previous: ASCII

#### 3.7.7 Comma-Separated Values

Writes tables in the semi-standard Comma-Separated Values format. This does not preserve any metadata apart from column names, and is generally inefficient to read, but it can be useful for importing into certain external applications, such as some databases or spreadsheets.

By default, the first line is a header line giving the column names, but this can be inhibited using the `header=false` configuration option.

The `delimiter` option makes it possible to use non-comma characters to separate fields. Depending on the character used this may behave in surprising ways; in particular for space-separated fields the `ascii` format may be a better choice.

The handler behaviour may be modified by specifying one or more comma-separated name=value configuration options in parentheses after the handler name, e.g. "`csv(header=true,delimiter=|)`". The following options are available:

`header = true|false`
  If true, the first line of the CSV output will be a header containing the column names; if false, no header line is written and all lines represent data rows. (Default: `true`)
`delimiter = <char>|0xNN`
  Field delimiter character, by default a comma. Permitted values are a single character like "`|`", a hexadecimal character code like "`0x7C`", or one of the names "`comma`", "`space`" or "`tab`". Some choices of delimiter, for instance whitespace characters, might not work well or might behave in surprising ways. (Default: `,`)
`maxCell = <int>`
  Maximum width in characters of an output table cell. Cells longer than this will be truncated. (Default: `2147483647`)

If no output format is explicitly chosen, writing to a filename with the extension "`.csv`" (case insensitive) will select `CSV` format for output.

An example looks like this:

    RECNO,SPECIES,NAME,LEGS,HEIGHT,MAMMAL
    1,pig,Pigling Bland,4,0.8,true
    2,cow,Daisy,4,2.0,true
    3,goldfish,Dobbin,,0.05,false
    4,ant,,6,0.001,false
    5,ant,,6,0.001,false
    6,queen ant,Ma'am,6,0.002,false
    7,human,Mark,2,1.8,true

The handler class for this format is `CsvTableWriter`.

Next Previous Up Contents
Next: Tab-Separated Table
Up: Supplied Output Handlers
Previous: ASCII

STIL - Starlink Tables Infrastructure Library
Starlink User Note252
STIL web page: http://www.starlink.ac.uk/stil/
Author email: m.b.taylor@bristol.ac.uk