Custom Functions

You will be able in this section to define your own functions, and use them the same way as the oder validation rules: calling them by name in your Settings object.

The first step is to create a ts file and a class that will contain all your functions

First Step

Create a new .ts file inside your project. To do it just as the example name it

validation-functions.ts

The first step is to import the class CustomValidationRuleResult from the project in the file custom-validation-rule-result.ts

After that, you will export the class ValidationFunctions, which will contain all your custom validation rules the same as this example:

EXAMPLE

Second Step

Inside your component (the same that will be receivig the spreadtheet file), you will have to import this ts file.

import { ValidationFunctions } from ‘./validation-functions/validation-functions’;

Inside your own validation function (refer to the installation an setup instructions), insert the next code

for (constpropertyofxlsxSettings.columnProperties) {
     if (property.customValidationRule) {
           property.customValidationRule.functions = newValidationFunctions();
      }
}

Third Step

Declare your xlsxSettings object, defining the property customValidationRules with your function name. Just as this example:

{

    “hasHeader”: true,

    “minColumns”: 1,

    “maxColumns”: 5,

    “columnProperties”: [

        {

            “position”: “1”,

            “name”: “email”,

            “customValidationRule”: {

                      “functionName”: isValidEmailCustomFunction” 

             }

        }

    ]

}