Usage

An example for the usage can be found in the example folder in the root of the package.

Here is the content as a quick reference.

example.py

from groundwork_spreadsheets import ExcelValidationPattern
from groundwork import App


def Application():
    app = App(plugins=[], strict=True)
    return app


class ReadCustomExcel(ExcelValidationPattern):
    def __init__(self, app, name=None, *args, **kwargs):
        self.name = name or self.__class__.__name__
        super(ReadCustomExcel, self).__init__(app, *args, **kwargs)

    def activate(self):
        pass

    def deactivate(self):
        pass


if __name__ == '__main__':
    app = App(config_files=['configuration.py'], plugins=[], strict=True)
    plugin = ReadCustomExcel(app)
    data = plugin.excel_validation.read_excel('config.json', 'example.xlsx')
    for row in data:
        headers = data[row]
        for header in headers:
            print("Row {0}, Header '{1}': {2}".format(row, header, data[row][header]))

config.json

{
    "sheet_config": "active",
    "orientation": "column_based",
    "headers_index_config": {
        "row_index": {
            "first": "automatic",
            "last": "automatic"
        },
        "column_index": {
            "first": "automatic",
            "last": "automatic"
        }
    },
    "data_index_config": {
        "row_index": {
            "first": "automatic",
            "last": "automatic"
        },
        "column_index": {
            "first": "automatic",
            "last": "automatic"
        }
    },
    "data_type_config": [
        {
            "header": "Date",
            "fail_on_type_error": false,
            "fail_on_empty_cell": false,
            "fail_on_header_not_found": true,
            "type": {
                "base": "date"
            }
        },
        {
            "header": "Enum",
            "fail_on_type_error": true,
            "fail_on_empty_cell": true,
            "fail_on_header_not_found": true,
            "type": {
                "base": "enum",
                "enum_values": ["ape", "dog", "cat"],
                "filter": {
                    "whitelist_values": ["ape", "cat"]
                }
            }
        },
        {
            "header": "Float",
            "fail_on_type_error": true,
            "fail_on_empty_cell": true,
            "fail_on_header_not_found": true,
            "type": {
                "base": "float",
                "minimum": 1.1,
                "maximum": 334
            }
        },
        {
            "header": "Integer",
            "fail_on_type_error": true,
            "fail_on_empty_cell": true,
            "fail_on_header_not_found": true,
            "type": {
                "base": "integer",
                "minimum": -3,
                "maximum": 30
            }
        },
        {
            "header": "Text",
            "fail_on_type_error": true,
            "fail_on_empty_cell": true,
            "fail_on_header_not_found": true,
            "type": {
                "base": "string",
                "pattern": "^Text [0-9]$"
            }
        }
    ],
    "filter_properties": {
        "excluded_fail_on_empty_cell": false,
        "excluded_fail_on_type_error": false,
        "excluded_enable_logging": false
    }
}