apache-poi NPOI: Data validation constraint approach for Date, Time , List Item , email etc. for XSSF(.xslx) excel file using c# Set the Date Constraints for Date Field Values Between 01/01/1900 To 12/31/2119 with Date Format mm/dd//yyyyy;


Example

  int DVRowLimit = (Int16.MaxValue); 
        CellRangeAddressList cellRangeFieldsType1 = new CellRangeAddressList(1, DVRowLimit, targetFirstCol, targetLastCol);
        XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)validationHelper.CreateDateConstraint(OperatorType.BETWEEN, "=DATE(1900,1,1)", "=DATE(2119,12,31)", "mm/dd/yyyyy");
    //dvConstraint = (XSSFDataValidationConstraint)validationHelper.CreateDateConstraint(OperatorType.IGNORED, "", "", "m/d/yy h:mm");
        XSSFDataValidation dataValidation = (XSSFDataValidation)validationHelper.CreateValidation(dvConstraint, cellRangeFieldsType1);
        dataValidation.ShowErrorBox = true;
        dataValidation.ErrorStyle = 0;
        dataValidation.CreateErrorBox("InvalidDate", "Allowed Format is MM/DD/YYYY");
        dataValidation.ShowErrorBox = true;
        dataValidation.CreatePromptBox("Date Data Validation", "Enter Date in Format MM/DD/YYYY.");
        dataValidation.ShowPromptBox = true;
        sheet.AddValidationData(dataValidation);