Spreadsheet (spreadsheet v0.2.3)

Parse Spreadsheet files using Rustler and Calamine.

File formats supported are .xls, .xla, .xlsx, .xlsm, .xlam, xlsb and .ods.

Usage

To retrieve sheet names:

iex> Spreadsheet.sheet_names("test_file_1.xlsx")

{:ok, ["sheet1"]}

Or from a binary:

iex> Spreadsheet.sheet_names_from_binary(File.read!("test_file_1.xlsx"))

{:ok, ["sheet1"]}

To retrieve rows:

iex> Spreadsheet.parse("test_file_1.xlsx")

{:ok, [["row1col1", "row1col2"], ["row2col1", "row2col2"]]}

Or from a binary:

iex> Spreadsheet.parse_from_binary(File.read!("test_file_1.xlsx"))

{:ok, [["row1col1", "row1col2"], ["row2col1", "row2col2"]]}

Note that all dates will be retrieved as NaiveDateTime, and all numbers as Float.

For further documentation on how rows gets parsed, view the Calamine documentation:

https://docs.rs/calamine/latest/calamine/

Summary

Functions

Returns a list of sheet names with options.

Returns a list of sheet names from binary content with options.

Functions

parse(path, sheet_name)

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

parse_from_binary(content, sheet_name)

@spec parse_from_binary(binary(), binary()) :: {:ok, list()} | {:error, String.t()}

sheet_names(path, opts \\ [])

@spec sheet_names(
  String.t(),
  keyword()
) :: {:ok, [String.t()]} | {:error, String.t()}

Returns a list of sheet names with options.

Options

  • :hidden - When false, excludes hidden sheets. Defaults to true.

sheet_names_from_binary(content, opts \\ [])

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

Returns a list of sheet names from binary content with options.

Options

  • :hidden - When false, excludes hidden sheets. Defaults to true.