encsv(X;FD;RD;QC;O)

Converts a table or query value X into CSV or other delimiter-separated text. (Available as of version 19.77)

Description

Currently, encsv(X;FD;RD;QC;O) must be called from the accum; typically, in the scalar context in block code.

Syntax

encsv(X;FD;RD;QC;O)

Input

Argument Type Description
X The table or query value to be converted to CSV format.
FD text The field delimiter in the CSV file. The default value is ','.
RD text The row delimiter in the CSV file. The default value is '\n'.
QC text The quote character in the CSV file. The default value is '"'.
O text

A list of 0 or more special options: 'format', 'noformat', 'dltb', 'nodltb', 'quoteall', 'names', 'labels', and 'nlswap'.

  • 'noformat' does not format data. This is the default option.
  • 'format' formats data according to column format.
  • 'dltb' deletes leading and trailing blanks from each field. This is the default option.
  • 'nodltb' leaves leading and trailing blanks.
  • 'quoteall' quotes all fields, whether or not it is necessary.
  • 'names' prefixes the CSV with a header row containing the MDB column names.
  • 'labels' prefixes the CSV with a header row containing the MDB column labels.
  • 'nlswap' swaps the two header rows if both names and labels are specified, putting labels before names.

Return Value

Returns a CSV or other delimiter-separated text. The functions throws an error if the data is too large. Currently, the limit is 1,00,000 total cells (calculated as number of rows x number of columns).

Cells in the header or the data that contain the field delimiter, row delimiter, or the quote character itself will be quoted in the CSV-compliant manner, by surrounding them with the quote character, and any occurrences of the quote character will be doubled in the field. For example (assuming " quote character), the string red, "white," and blue will appear as "red, ""white,"" and blue". Note that formatted numbers containing commas will naturally be quoted if the field delimiter is ','. If the 'quoteall' option is specified, all fields will be quoted whether or not they contain the delimiter or quote character.