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

delete_dir(dir \\ "./temp")

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
extract_xml_to_file(file_list, path)

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 in char_list format
  • path - file path of a .xlsx file type in string 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
validate_path_all_indexes(path)

Checks if given path is a valid file type, returning a list of available worksheets.

Parameters

  • path - file path of a .xlsx file type in string 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, []}
validate_path_and_index(path, index)

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 in string 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."}
xml_file_list(index)

List of files contained in the requested .xlsx file to be extracted.

Parameters

  • index - index of the .xlsx worksheet to be parsed

Example

iex> Xlsxir.Unzip.xml_file_list(0)
   ['xl/styles.xml', 'xl/sharedStrings.xml', 'xl/worksheets/sheet1.xml']