file.excel

file.excel.convert_dict(d):

Convert a dictionary to a list that can be written to excel

Parameters:

d – Dictionary which should be converted

Returns:

List with the dict values

Return type:

list

file.excel.get_worksheets(path, **kwargs):

Gets all available worksheets within a xlsx-file and returns a list

Parameters:

path (str) – Path to excel file

Returns:

Returns a list with all worksheets within the excel-file

Return type:

list

file.excel.load(path, **kwargs):

Loads an xlsx file and returns it’s content as datastructure.

Parameters:

path (str) – Path to xlsx file eg. /home/user/documents/demo.xlsx

Returns:

a list of dict

Return type:

list of dict

Keyword Arguments:
  • work_sheet_name (str) –

    Name of the worksheet to return data from, defaults to Sheet1 if neither work_sheet_name nor Sheet1 is found the worksheet on index 0 is used.

file.excel.save(data, destination_path, **kwargs):

Generate a xlsx file from a datastructure. Currently just a single sheet is supported

Parameters:
  • data (list of dict) – Currently data must be a list of dicts.

  • destination_path (str) – Path of the resulting CSV file.

Raises:

ValueError – If the format of data cannot be determined.

Returns:

Returns True on success.

Return type:

bool

Keyword Arguments:

Currently None

file.excel.to_csv(src_path, target_path=None, **kwargs):

This function converts an excel file to a CSV file. If the target_path parameter is omitted, it will be constructed from the src_path. Eg. /home/user/test.xlsx -> /home/user/test.csv

Parameters:
  • src_path (str) – Path to source excel file which should be converted

  • target_path (str, optional) – Target path for the converted CSV file, defaults to None

Returns:

Returns True on success

Return type:

boolean

file.excel.to_csv_ws(src_path, target_path=None, **kwargs):

This function converts an excel file to a CSV file creating a file for each worksheet. If the target_path parameter is omitted, it will be constructed from the src_path. Eg. /home/user/test.xlsx -> /home/user/test.csv

Parameters:
  • src_path (str) – Path to source excel file which should be converted

  • target_path (str, optional) – Target path for the converted CSV file, defaults to None

Keyword Arguments:
  • ws_separator (str) –

    String which shall be used to separate the filename from the worksheet. Default: __ file.xlsx –> file__worksheet.csv

  • ws_names (list) –

    List of worksheets that should be converted to CSV. If not defined all worksheets will be converted. If worksheet does not exist an error will be logged, the return-value will not be changed

Returns:

Returns True on success

Return type:

boolean