Xlsxir v1.6.4 Xlsxir.Unzip View Source
Provides validation of accepted file types for file path,
extracts required .xlsx contents to memory or files
Link to this section Summary
Functions
Extracts requested list of files from a .zip file to memory or file system
and returns a list of the extracted file paths
Checks if given path is a valid file type, returning a list of available worksheets
Checks if given path is a valid file type and contains the requested worksheet, returning a tuple
Link to this section Functions
extract_xml(file_list, path, to) View Source
Extracts requested list of files from a .zip file to memory or file system
and returns a list of the extracted file paths.
Parameters
file_list- list containing file paths to be extracted inchar_listformatpath- file path of a.xlsxfile type instringformatto-:memoryor{:file, "destination/path"}option
Example
An example file named test.zip located in './test_data/test' containing a single file named test.txt:
iex> path = "./test/test_data/test.zip"
iex> file_list = ['test.txt']
iex> Xlsxir.Unzip.extract_xml(file_list, path, :memory)
{:ok, [%Xlsxir.XmlFile{content: "test_successful", name: "test.txt", path: nil}]}
iex> Xlsxir.Unzip.extract_xml(file_list, path, {:file, "temp/"})
{:ok, [%Xlsxir.XmlFile{content: nil, name: "test.txt", path: "temp/test.txt"}]}
iex> with {:ok, _} <- File.rm_rf("temp"), do: :ok
:ok
validate_path_all_indexes(path) View Source
Checks if given path is a valid file type, returning a list of available worksheets.
Parameters
path- file path of a.xlsxfile type instringformat
Example
iex> path = "./test/test_data/test.xlsx"
iex> Xlsxir.Unzip.validate_path_all_indexes(path)
{:ok, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
iex> path = "./test/test_data/test.zip"
iex> Xlsxir.Unzip.validate_path_all_indexes(path)
{:ok, []}
iex> path = "./test/test_data/test.invalidfile"
iex> Xlsxir.Unzip.validate_path_all_indexes(path)
{:error, "Invalid file type (expected xlsx)."}
validate_path_and_index(path, index) View Source
Checks if given path is a valid file type and contains the requested worksheet, returning a tuple.
Parameters
path- file path of a.xlsxfile type instringformat
Example
iex> path = "./test/test_data/test.xlsx"
iex> Xlsxir.Unzip.validate_path_and_index(path, 0)
{:ok, './test/test_data/test.xlsx'}
iex> path = "./test/test_data/test.validfilebutnotxlsx"
iex> Xlsxir.Unzip.validate_path_and_index(path, 0)
{:ok, './test/test_data/test.validfilebutnotxlsx'}
iex> path = "./test/test_data/test.xlsx"
iex> Xlsxir.Unzip.validate_path_and_index(path, 100)
{:error, "Invalid worksheet index."}
iex> path = "./test/test_data/test.invalidfile"
iex> Xlsxir.Unzip.validate_path_and_index(path, 0)
{:error, "Invalid file type (expected xlsx)."}