Xlsxir v1.0.0 Xlsxir
Extracts and parses data from a .xlsx
file to an Erlang Term Storage (ETS) process and provides various functions for accessing the data.
Summary
Functions
Deletes ETS process :worksheet
and returns :ok
if successful
Extracts worksheet data contained in the specified .xlsx
file to an ETS process named :worksheet
which is accessed via the Xlsxir.Worksheet
module. Successful extraction
returns :ok
with the timer argument set to false and returns a tuple of {:ok, time}
where time is a list containing time elapsed during the extraction process
(i.e. [hour, minute, second, microsecond]
) when the timer argument is set to true
Accesses :worksheet
ETS process and returns value of specified cell. Note: entire worksheet is traversed each time this function is executed. Use with caution as
this would be an expensive task for a large worksheet
Accesses :worksheet
ETS process and returns values of specified column in a list
Accesses :worksheet
ETS process and returns data formatted as a list of row value lists
Accesses :worksheet
ETS process and returns data formatted as a map of cell references and values
Accesses :worksheet
ETS process and returns values of specified row in a list
. Blank rows are not counted
Functions
Deletes ETS process :worksheet
and returns :ok
if successful.
Example
Extract first worksheet in an example file named test.xlsx
located in ./test/test_data
:
iex> Xlsxir.extract("./test/test_data/test.xlsx", 0)
:ok
iex> Xlsxir.close
:ok
Extracts worksheet data contained in the specified .xlsx
file to an ETS process named :worksheet
which is accessed via the Xlsxir.Worksheet
module. Successful extraction
returns :ok
with the timer argument set to false and returns a tuple of {:ok, time}
where time is a list containing time elapsed during the extraction process
(i.e. [hour, minute, second, microsecond]
) when the timer argument is set to true.
Cells containing formulas in the worksheet are extracted as either a string
, integer
or float
depending on the resulting value of the cell.
Cells containing an ISO 8601 date format are extracted and converted to Erlang :calendar.date()
format (i.e. {year, month, day}
).
Parameters
path
- file path of a.xlsx
file type instring
formatindex
- index of worksheet from within the Excel workbook to be parsed (zero-based index)timer
- boolean flag that tracts extraction process time and returns it when set totrue
. Defalut value isfalse
.
Example
Extract first worksheet in an example file named test.xlsx
located in ./test/test_data
:
iex> Xlsxir.extract("./test/test_data/test.xlsx", 0)
:ok
iex> Xlsxir.Worksheet.alive?
true
iex> Xlsxir.close
:ok
Accesses :worksheet
ETS process and returns value of specified cell. Note: entire worksheet is traversed each time this function is executed. Use with caution as
this would be an expensive task for a large worksheet.
Parameters
cell_ref
- Reference name of cell to be returned instring
format (i.e."A1"
)
Example
An example file named test.xlsx
located in ./test/test_data
containing the following:
- cell ‘A1’ -> “string one”
- cell ‘B1’ -> “string two”
- cell ‘C1’ -> integer of 10
- cell ‘D1’ -> formula of “4 * 5”
cell ‘E1’ -> date of 1/1/2016 or Excel date serial of 42370
iex> Xlsxir.extract("./test/test_data/test.xlsx", 0) :ok iex> Xlsxir.get_cell("A1") "string one" iex> Xlsxir.close :ok
Accesses :worksheet
ETS process and returns values of specified column in a list
.
Parameters
col
- Reference name of column to be returned instring
format (i.e."A"
)
Example
An example file named test.xlsx
located in ./test/test_data
containing the following:
- cell ‘A1’ -> “string one”
- cell ‘B1’ -> “string two”
- cell ‘C1’ -> integer of 10
- cell ‘D1’ -> formula of “4 * 5”
cell ‘E1’ -> date of 1/1/2016 or Excel date serial of 42370
iex> Xlsxir.extract("./test/test_data/test.xlsx", 0) :ok iex> Xlsxir.get_col("A") ["string one"] iex> Xlsxir.close :ok
Accesses :worksheet
ETS process and returns data formatted as a list of row value lists.
Example
An example file named test.xlsx
located in ./test/test_data
containing the following:
- cell ‘A1’ -> “string one”
- cell ‘B1’ -> “string two”
- cell ‘C1’ -> integer of 10
- cell ‘D1’ -> formula of “4 * 5”
cell ‘E1’ -> date of 1/1/2016 or Excel date serial of 42370
iex> Xlsxir.extract("./test/test_data/test.xlsx", 0) :ok iex> Xlsxir.get_list [["string one", "string two", 10, 20, {2016, 1, 1}]] iex> Xlsxir.close :ok
Accesses :worksheet
ETS process and returns data formatted as a map of cell references and values.
Example
An example file named test.xlsx
located in ./test/test_data
containing the following:
- cell ‘A1’ -> “string one”
- cell ‘B1’ -> “string two”
- cell ‘C1’ -> integer of 10
- cell ‘D1’ -> formula of “4 * 5”
cell ‘E1’ -> date of 1/1/2016 or Excel date serial of 42370
iex> Xlsxir.extract("./test/test_data/test.xlsx", 0) :ok iex> Xlsxir.get_map %{ "A1" => "string one", "B1" => "string two", "C1" => 10, "D1" => 20, "E1" => {2016,1,1}} iex> Xlsxir.close :ok
Accesses :worksheet
ETS process and returns values of specified row in a list
. Blank rows are not counted.
Parameters
row
- Reference name of row to be returned ininteger
format (i.e.1
)
Example
An example file named test.xlsx
located in ./test/test_data
containing the following:
- cell ‘A1’ -> “string one”
- cell ‘B1’ -> “string two”
- cell ‘C1’ -> integer of 10
- cell ‘D1’ -> formula of “4 * 5”
cell ‘E1’ -> date of 1/1/2016 or Excel date serial of 42370
iex> Xlsxir.extract("./test/test_data/test.xlsx", 0) :ok iex> Xlsxir.get_row(1) ["string one", "string two", 10, 20, {2016, 1, 1}] iex> Xlsxir.close :ok