/// <summary>
        /// Create the cell style
        /// </summary>
        /// <param name="colourName">string</param>
        /// <param name="type">COBieAllowedType</param>
        private void CreateStyle(string colourName, COBieAllowedType type)
        {
            ICellStyle cellStyle;

            cellStyle = ExcelWorkbook.CreateCellStyle();

            if (IsXlsx)
            {
                ((XSSFCellStyle)cellStyle).FillForegroundXSSFColor = (XSSFColor)_colours[colourName];
            }
            else
            {
                cellStyle.FillForegroundColor = _colours[colourName].Indexed;
            }

            cellStyle.FillPattern = FillPattern.SolidForeground;

            cellStyle.BorderBottom = BorderStyle.Thin;
            cellStyle.BorderLeft   = BorderStyle.Thin;
            cellStyle.BorderRight  = BorderStyle.Thin;
            cellStyle.BorderTop    = BorderStyle.Thin;
            AppendFormat(type, cellStyle); //add format for value display

            // TODO:maybe clone from the template?
            var tuple = new Tuple <string, COBieAllowedType>(colourName, type);

            _cellStyles.Add(tuple, cellStyle);
        }
Example #2
0
 public COBieAttributes(int order, COBieKeyType keyType, string referenceColumnName, COBieAttributeState state, string columnName, int maxLength, COBieAllowedType allowedType, COBieCardinality cardinality = COBieCardinality.OneToMany)
 {
     _state = state;
     _maxLength = maxLength;
     _allowedType = allowedType;
     _order = order;
     _columnName = columnName;
     _keyType = keyType;
     _referenceColumnName = referenceColumnName;
     _cardinality = cardinality;
 }
Example #3
0
 public COBieAttributes(int order, COBieKeyType keyType, string referenceColumnName, COBieAttributeState state, string columnName, int maxLength, COBieAllowedType allowedType, COBieCardinality cardinality = COBieCardinality.OneToMany)
 {
     _state               = state;
     _maxLength           = maxLength;
     _allowedType         = allowedType;
     _order               = order;
     _columnName          = columnName;
     _keyType             = keyType;
     _referenceColumnName = referenceColumnName;
     _cardinality         = cardinality;
 }
        private void CreateFormat(COBieAllowedType type, string formatString, string colourName)
        {
            HSSFCellStyle cellStyle;

            cellStyle = XlsWorkbook.CreateCellStyle() as HSSFCellStyle;

            HSSFDataFormat dataFormat = XlsWorkbook.CreateDataFormat() as HSSFDataFormat;

            cellStyle.DataFormat = dataFormat.GetFormat(formatString);

            cellStyle.FillForegroundColor = _colours[colourName].Indexed;
            cellStyle.FillPattern         = FillPattern.SolidForeground;

            cellStyle.BorderBottom = BorderStyle.Thin;
            cellStyle.BorderLeft   = BorderStyle.Thin;
            cellStyle.BorderRight  = BorderStyle.Thin;
            cellStyle.BorderTop    = BorderStyle.Thin;

            // TODO:maybe clone from the template?
            _cellStyles.Add(type, cellStyle);
        }
        /// <summary>
        /// Append the required format depending on the COBieAllowedType
        /// </summary>
        /// <param name="type">COBieAllowedType</param>
        /// <param name="cellStyle">ICellStyle, style to ally formate to</param>
        private void AppendFormat(COBieAllowedType type, ICellStyle cellStyle)
        {
            string formatString = null;

            switch (type)
            {
            case COBieAllowedType.ISODate:
                formatString = "yyyy-MM-dd";
                break;

            case COBieAllowedType.ISODateTime:
                formatString = "yyyy-MM-ddThh:mm:ss";
                break;

            case COBieAllowedType.AlphaNumeric:
                break;

            case COBieAllowedType.Email:
                break;

            case COBieAllowedType.Numeric:
                break;

            case COBieAllowedType.Text:
                break;

            case COBieAllowedType.AnyType:
                break;

            default:
                break;
            }
            if (formatString != null)
            {
                IDataFormat dataFormat = ExcelWorkbook.CreateDataFormat();
                cellStyle.DataFormat = dataFormat.GetFormat(formatString);
            }
        }
        private void CreateFormat(COBieAllowedType type, string formatString, string colourName)
        {
            var cellStyle  = XlsWorkbook.CreateCellStyle() as HSSFCellStyle;
            var dataFormat = XlsWorkbook.CreateDataFormat() as HSSFDataFormat;

            if (cellStyle == null || dataFormat == null)
            {
                Log.LogWarning("Error producing Excel cell style or format in workbook.");
                return;
            }

            cellStyle.DataFormat = dataFormat.GetFormat(formatString);

            cellStyle.FillForegroundColor = _colours[colourName].Indexed;
            cellStyle.FillPattern         = FillPattern.SolidForeground;

            cellStyle.BorderBottom = BorderStyle.Thin;
            cellStyle.BorderLeft   = BorderStyle.Thin;
            cellStyle.BorderRight  = BorderStyle.Thin;
            cellStyle.BorderTop    = BorderStyle.Thin;

            // TODO:maybe clone from the template?
            _cellStyles.Add(type, cellStyle);
        }
Example #7
0
        /// <summary>
        /// check for Field format Error in passed cell
        /// </summary>
        /// <param name="cell">COBieCell</param>
        /// <param name="sheetName">Sheet name</param>
        /// <param name="row">Row index</param>
        /// <param name="col">Column index</param>
        /// <param name="initialRowHash">Initial row hash value</param>
        /// <returns>COBieError or null</returns>
        public COBieError GetCOBieFieldFormatError(COBieCell cell, COBieAttributeState state, COBieError.ErrorLevels errorLevel, string sheetName, int row, int col, string initialRowHash)
        {
            COBieError err = new COBieError(sheetName, cell.COBieColumn.ColumnName, "", COBieError.ErrorTypes.None, COBieError.ErrorLevels.None, initialRowHash, col, row);


            int maxLength = cell.COBieColumn.ColumnLength;
            COBieAllowedType allowedType = cell.COBieColumn.AllowedType;

            if ((state == COBieAttributeState.Required_IfSpecified) ||
                (state == COBieAttributeState.Required_System) ||
                (state == COBieAttributeState.Required_System_IfSpecified)
                ) //if a required value but marked as n/a then do not class as error
            {
                if (cell.CellValue == Constants.DEFAULT_STRING)
                {
                    return(null);
                }
            }

            //check cell.COBieColumn.AllowedType for format errors
            switch (allowedType)
            {
            case COBieAllowedType.AlphaNumeric:
                if (!cell.IsAlphaNumeric())
                {
                    err.ErrorDescription = ErrorDescription.AlphaNumeric_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.AlphaNumeric_Value_Expected;
                }
                break;

            case COBieAllowedType.Email:
                if (!cell.IsEmailAddress())
                {
                    err.ErrorDescription = ErrorDescription.ISODate_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.ISODate_Value_Expected;
                }
                break;

            case COBieAllowedType.ISODate:
            case COBieAllowedType.ISODateTime:
                if (!cell.IsDateTime())
                {
                    err.ErrorDescription = ErrorDescription.ISODate_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.ISODate_Value_Expected;
                }
                break;

            case COBieAllowedType.Numeric:
                if (!cell.IsNumeric())
                {
                    err.ErrorDescription = ErrorDescription.Numeric_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.Numeric_Value_Expected;
                }
                break;

            case COBieAllowedType.AnyType:
            case COBieAllowedType.Text:
                if (!cell.IsText())
                {
                    err.ErrorDescription = ErrorDescription.Text_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.Text_Value_Expected;
                }
                break;

            default:
                break;
            }
            if (err.ErrorType != COBieError.ErrorTypes.None)
            {
                err.FieldValue = cell.CellValue;
                if (err.ErrorLevel == COBieError.ErrorLevels.None) //if set above, just in case we do set above
                {
                    err.ErrorLevel = errorLevel;
                }
                return(err);
            }
            return(null);
        }
        /// <summary>
        /// Create the cell style
        /// </summary>
        /// <param name="colourName">string</param>
        /// <param name="type">COBieAllowedType</param>
        private void CreateStyle(string colourName, COBieAllowedType type)
        {
            ICellStyle cellStyle;
            cellStyle = ExcelWorkbook.CreateCellStyle() ;

            if (IsXlsx)
            {
                ((XSSFCellStyle)cellStyle).FillForegroundXSSFColor = (XSSFColor)_colours[colourName];
            }
            else
            {
                    cellStyle.FillForegroundColor = _colours[colourName].Indexed;
            }
            
            cellStyle.FillPattern = FillPattern.SolidForeground;

            cellStyle.BorderBottom = BorderStyle.Thin;
            cellStyle.BorderLeft = BorderStyle.Thin;
            cellStyle.BorderRight = BorderStyle.Thin;
            cellStyle.BorderTop = BorderStyle.Thin;
            AppendFormat(type,cellStyle); //add format for value display

            // TODO:maybe clone from the template?
            var tuple = new Tuple<string, COBieAllowedType>(colourName, type);
            _cellStyles.Add(tuple, cellStyle);
        }
 /// <summary>
 /// Append the required format depending on the COBieAllowedType
 /// </summary>
 /// <param name="type">COBieAllowedType</param>
 /// <param name="cellStyle">ICellStyle, style to ally formate to</param>
 private void AppendFormat(COBieAllowedType type, ICellStyle cellStyle)
 {
     string formatString = null;
     switch (type)
     {
         case COBieAllowedType.ISODate:
             formatString = "yyyy-MM-dd";
             break;
         case COBieAllowedType.ISODateTime:
             formatString = "yyyy-MM-ddThh:mm:ss";
             break;
         case COBieAllowedType.AlphaNumeric:
             break;
         case COBieAllowedType.Email:
             break;
         case COBieAllowedType.Numeric:
             break;
         case COBieAllowedType.Text:
             break;
         case COBieAllowedType.AnyType:
             break;
         default:
             break;
     }
     if (formatString != null)
     {
         IDataFormat dataFormat = ExcelWorkbook.CreateDataFormat();
         cellStyle.DataFormat = dataFormat.GetFormat(formatString);
     }
 }
        private void CreateFormat(COBieAllowedType type, string formatString, string colourName)
        {
            HSSFCellStyle cellStyle;
            cellStyle = XlsWorkbook.CreateCellStyle() as HSSFCellStyle;
 
            HSSFDataFormat dataFormat = XlsWorkbook.CreateDataFormat() as HSSFDataFormat;
            cellStyle.DataFormat = dataFormat.GetFormat(formatString);
            
            cellStyle.FillForegroundColor = _colours[colourName].Indexed;
            cellStyle.FillPattern = FillPattern.SolidForeground;

            cellStyle.BorderBottom = BorderStyle.Thin;
            cellStyle.BorderLeft = BorderStyle.Thin;
            cellStyle.BorderRight = BorderStyle.Thin;
            cellStyle.BorderTop = BorderStyle.Thin;

            // TODO:maybe clone from the template?
            _cellStyles.Add(type, cellStyle);
        }