Xlsxir v1.5.0 Xlsxir.Unzip
Provides validation of accepted file types for file path, extracts required .xlsx
contents to ./temp
and ultimately deletes the ./temp
directory and its contents.
Summary
Functions
Deletes all files and directories contained in specified directory
Extracts requested list of files from a .zip
file to ./temp
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
List of files contained in the requested .xlsx
file to be extracted
Functions
Deletes all files and directories contained in specified directory.
Parameters
dir
- list of directories to delete (default set for standard Xlsxir functionality)
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_to_file(file_list, path)
{:ok, ['temp/test.txt']}
iex> Xlsxir.Unzip.delete_dir("./temp")
:ok
Extracts requested list of files from a .zip
file to ./temp
and returns a list of the extracted file paths.
Parameters
file_list
- list containing file paths to be extracted inchar_list
formatpath
- file path of a.xlsx
file type instring
format
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_to_file(file_list, path)
{:ok, ['temp/test.txt']}
iex> File.ls("./temp")
{:ok, ["test.txt"]}
iex> Xlsxir.Unzip.delete_dir("./temp")
:ok
Checks if given path is a valid file type, returning a list of available worksheets.
Parameters
path
- file path of a.xlsx
file type instring
format
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]}
iex> path = "./test/test_data/test.zip"
iex> Xlsxir.Unzip.validate_path_all_indexes(path)
{:ok, []}
Checks if given path is a valid file type and contains the requested worksheet, returning a tuple.
Parameters
path
- file path of a.xlsx
file type instring
format
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."}