PhoenixKitCatalogue.Import.Parser (PhoenixKitCatalogue v0.1.14)

Copy Markdown View Source

Parses XLSX and CSV files into structured row data.

Returns a map with headers, rows, sheet names, and row count. Uses no external dependencies beyond what phoenix_kit already provides:

  • NimbleCSV for CSV (auto-detects separator)
  • XlsxReader for XLSX

Summary

Functions

Detects file format from the filename extension.

Lists sheet names from an XLSX file.

Parses a file binary into structured data.

Types

parsed_file()

@type parsed_file() :: %{
  sheets: [String.t()],
  headers: [String.t()],
  rows: [[String.t()]],
  row_count: non_neg_integer()
}

Functions

detect_format(filename)

@spec detect_format(String.t()) :: :xlsx | :csv | {:error, :unsupported}

Detects file format from the filename extension.

list_sheets(binary)

@spec list_sheets(binary()) :: {:ok, [String.t()]} | {:error, term()}

Lists sheet names from an XLSX file.

parse(binary, filename, opts \\ [])

@spec parse(binary(), String.t(), keyword()) ::
  {:ok, parsed_file()} | {:error, term()}

Parses a file binary into structured data.

Options

  • :sheet — sheet name to parse (XLSX only, defaults to first sheet)