Beispiel #1
0
 public XSSFDataValidation(XSSFDataValidationConstraint constraint, CellRangeAddressList regions, CT_DataValidation ctDataValidation)
     : base()
 {
     this.validationConstraint = constraint;
     this.ctDdataValidation    = ctDataValidation;
     this.regions = regions;
 }
Beispiel #2
0
        private static XSSFDataValidationConstraint GetConstraint(CT_DataValidation ctDataValidation)
        {
            XSSFDataValidationConstraint constraint = null;
            String formula1 = ctDataValidation.formula1;
            String formula2 = ctDataValidation.formula2;
            ST_DataValidationOperator operator1 = ctDataValidation.@operator;
            ST_DataValidationType     type      = ctDataValidation.type;
            int validationType = XSSFDataValidation.validationTypeReverseMappings[type];
            int operatorType   = XSSFDataValidation.operatorTypeReverseMappings[operator1];

            constraint = new XSSFDataValidationConstraint(validationType, operatorType, formula1, formula2);
            return(constraint);
        }
Beispiel #3
0
        /* (non-Javadoc)
         * @see Npoi.Core.ss.usermodel.DataValidationHelper#CreateValidation(Npoi.Core.ss.usermodel.DataValidationConstraint, Npoi.Core.ss.util.CellRangeAddressList)
         */

        public IDataValidation CreateValidation(IDataValidationConstraint constraint, CellRangeAddressList cellRangeAddressList)
        {
            XSSFDataValidationConstraint dataValidationConstraint = (XSSFDataValidationConstraint)constraint;
            CT_DataValidation            newDataValidation        = new CT_DataValidation();

            int validationType = constraint.GetValidationType();

            switch (validationType)
            {
            case ValidationType.LIST:
                newDataValidation.type     = (ST_DataValidationType.list);
                newDataValidation.formula1 = (constraint.Formula1);
                break;

            case ValidationType.ANY:
                newDataValidation.type = ST_DataValidationType.none;
                break;

            case ValidationType.TEXT_LENGTH:
                newDataValidation.type = ST_DataValidationType.textLength;
                break;

            case ValidationType.DATE:
                newDataValidation.type = ST_DataValidationType.date;
                break;

            case ValidationType.INTEGER:
                newDataValidation.type = ST_DataValidationType.whole;
                break;

            case ValidationType.DECIMAL:
                newDataValidation.type = ST_DataValidationType.@decimal;
                break;

            case ValidationType.TIME:
                newDataValidation.type = ST_DataValidationType.time;
                break;

            case ValidationType.FORMULA:
                newDataValidation.type = ST_DataValidationType.custom;
                break;

            default:
                newDataValidation.type = ST_DataValidationType.none;
                break;
            }

            if (validationType != ValidationType.ANY && validationType != ValidationType.LIST)
            {
                newDataValidation.@operator = ST_DataValidationOperator.between;
                if (XSSFDataValidation.operatorTypeMappings.ContainsKey(constraint.Operator))
                {
                    newDataValidation.@operator = XSSFDataValidation.operatorTypeMappings[constraint.Operator];
                }

                if (constraint.Formula1 != null)
                {
                    newDataValidation.formula1 = (constraint.Formula1);
                }
                if (constraint.Formula2 != null)
                {
                    newDataValidation.formula2 = (constraint.Formula2);
                }
            }

            CellRangeAddress[] cellRangeAddresses = cellRangeAddressList.CellRangeAddresses;
            string             sqref = string.Empty;

            for (int i = 0; i < cellRangeAddresses.Length; i++)
            {
                CellRangeAddress cellRangeAddress = cellRangeAddresses[i];
                if (sqref.Length == 0)
                {
                    sqref = cellRangeAddress.FormatAsString();
                }
                else
                {
                    sqref = " " + cellRangeAddress.FormatAsString();
                }
            }
            newDataValidation.sqref      = sqref;
            newDataValidation.allowBlank = (true);
            newDataValidation.errorStyle = ST_DataValidationErrorStyle.stop;
            return(new XSSFDataValidation(dataValidationConstraint, cellRangeAddressList, newDataValidation));
        }