csv_parser v0.0.1 CsvParser

Link to this section Summary

Functions

Creates a new object to be passed into reduce!/3. new and reduce exist separately so that errors in your files can be handled explicitly.

Raises if path represents an invalid file

Reads the file returning a list of list. See new/2 for valid opts

Reads the file returning a list of list or raises on error

Reduces over the parsed file, calling fun/2 for each row.

Link to this section Functions

Link to this function

new(path, opts \\ [])

Creates a new object to be passed into reduce!/3. new and reduce exist separately so that errors in your files can be handled explicitly.

opts:

type: :csv | :xlsx  defaults to nil, which will auto-detect
sheet_index: index (index) of the sheet to parse. Default to nil,
             which will take the first sheet, only applicable to xlsx

For CSV, opts is passed as-is to the CSV library, so any of those options are valid. See: https://hexdocs.pm/csv/CSV.html#decode/2-options

Link to this function

new!(path, opts \\ [])

Raises if path represents an invalid file

Link to this function

read(path, opts \\ [])

Reads the file returning a list of list. See new/2 for valid opts

Link to this function

read!(path, opts \\ [])

Reads the file returning a list of list or raises on error

Link to this function

reduce!(csv, acc, fun)

Reduces over the parsed file, calling fun/2 for each row.

Example: csv = CsvParser.new!("sample.xlsx") rows = Enum.reduce(csv, [], fn {row, rows} -> [row | rows] end)