sdtables.sdtables
xlTables - Load/generate table data with Excel from python dictionary structures
cunningr - 2020
Requires openpyxl >= 2.6.2, jsonschema
SdTables Objects
class SdTables()
load_xlsx_file
| load_xlsx_file(file, data_only=False)
Method used to load an xlsx file containing one or more tables
Returns:
get_table_as_dict
| get_table_as_dict(table_name, fill_empty=False, string_only=False)
Takes a table name and returns the data as list of dictionaries
Arguments:
table_name
- Name of the table namefill_empty
- By default and empty cell will have a value None. fill_empty will replace None with the empty string ""string_only
- Enforce that all cell values convert to strings
Returns:
A dictionary (key=table_name) with a list of dictionaries (rows)
get_all_tables_as_dict
| get_all_tables_as_dict(flatten=False, squash=False, fill_empty=False, string_only=False)
Returns all table data. When dealing with tables from xlsx, by default each table is nested in a dictionary using the worksheet names as the key E.g.
{ "worksheet_name": [ { "table_name": [{"col1": "value", "col2": "value"}]} ] }
Arguments:
flatten
- Removes the worksheet_name hierarchy from the returned dictionary when using xlxs as sourcesquash
- Replaces the table_name with the worksheet_name when using xlsx as source. Only one table per worksheet allowed and ignores additional tablesfill_empty
- By default and empty cell will have a value None. fill_empty will replace None with the empty string ""string_only
- Enforce that all cell values convert to strings (E.g. for xlsx formulae)
Returns:
A list of dictionaries (rows)