Clojure-CSV is a small library for reading and writing CSV files. It correctly handles common CSV edge-cases, such as embedded newlines, commas, and quotes. The main functions are parse-csv and write-csv.
Clojure-CSV is a small library for reading and writing CSV files. It correctly handles common CSV edge-cases, such as embedded newlines, commas, and quotes. The main functions are parse-csv and write-csv.
(parse-csv csv & {:as opts})
Takes a CSV as a string or Reader and returns a seq of the parsed CSV rows, in the form of a lazy sequence of vectors: a vector per row, a string for each cell.
Accepts a number of keyword arguments to change the parsing behavior: :delimiter - A character that contains the cell separator for each column in a row. Default value: , :end-of-line - A string containing the end-of-line character for reading CSV files. If this setting is nil then \n and \r\n are both accepted. Default value: nil :quote-char - A character that is used to begin and end a quoted cell. Default value: " :strict - If this variable is true, the parser will throw an exception on parse errors that are recoverable but not to spec or otherwise nonsensical. Default value: false
Takes a CSV as a string or Reader and returns a seq of the parsed CSV rows, in the form of a lazy sequence of vectors: a vector per row, a string for each cell. Accepts a number of keyword arguments to change the parsing behavior: :delimiter - A character that contains the cell separator for each column in a row. Default value: \, :end-of-line - A string containing the end-of-line character for reading CSV files. If this setting is nil then \n and \r\n are both accepted. Default value: nil :quote-char - A character that is used to begin and end a quoted cell. Default value: \" :strict - If this variable is true, the parser will throw an exception on parse errors that are recoverable but not to spec or otherwise nonsensical. Default value: false
(quote-and-escape cell delimiter quote-char force-quote)
Given a string (cell), returns a new string that has any necessary quoting and escaping.
Given a string (cell), returns a new string that has any necessary quoting and escaping.
(write-csv table
&
{:keys [delimiter quote-char end-of-line force-quote]
:or
{delimiter \, quote-char \" end-of-line "\n" force-quote false}})
Given a sequence of sequences of strings, returns a string of that table in CSV format, with all appropriate quoting and escaping.
Accepts a number of keyword arguments to change the output: :delimiter - A character that contains the cell separator for each column in a row. Default value: , :end-of-line - A string containing the end-of-line character for writing CSV files. Default value: \n :quote-char - A character that is used to begin and end a quoted cell. Default value: " :force-quote - Forces every cell to be quoted (useful for Excel interop) Default value: false
Given a sequence of sequences of strings, returns a string of that table in CSV format, with all appropriate quoting and escaping. Accepts a number of keyword arguments to change the output: :delimiter - A character that contains the cell separator for each column in a row. Default value: \, :end-of-line - A string containing the end-of-line character for writing CSV files. Default value: \n :quote-char - A character that is used to begin and end a quoted cell. Default value: \" :force-quote - Forces every cell to be quoted (useful for Excel interop) Default value: false
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close