Ejemplo n.º 1
0
        public COBieCell this[int i]
        {
            get
            {
                COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault();
                if (cobieColumn != null)
                {
                    object pVal = cobieColumn.PropertyInfo.GetValue(this, null);

                    string cellValue = (pVal != null) ? pVal.ToString() : Constants.DEFAULT_STRING;
                    COBieCell thiscell = new COBieCell(cellValue, cobieColumn);
                    return thiscell;
                }
                
                
                return null;
            }
            set
            {
                COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault();
                if (cobieColumn != null)
                    cobieColumn.PropertyInfo.SetValue(this, value.CellValue, null);

            }
            
        }
Ejemplo n.º 2
0
        private bool SetCellTypedValue(ICell excelCell, COBieCell cell)
        {
            bool processed = false;

            try
            {
                if (String.IsNullOrEmpty(cell.CellValue) || cell.CellValue == Constants.DEFAULT_STRING)
                {
                    return false;
                }

                // We need to set the value in the most appropriate overload of SetCellValue, so the parsing/formatting is correct
                switch (cell.COBieColumn.AllowedType)
                {
                    case COBieAllowedType.ISODateTime:
                    case COBieAllowedType.ISODate:
                        DateTime date;
                        if (DateTime.TryParse(cell.CellValue, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out date))
                        {
                            excelCell.SetCellValue(date);
                            processed = true;
                        }
                        break;

                    case COBieAllowedType.Numeric:
                        Double val;
                        if (Double.TryParse(cell.CellValue, out val))
                        {
                            excelCell.SetCellValue(val);
                            processed = true;
                        }
                        break;

                    default:
                        break;
                }
            }
            catch (SystemException)
            { /* Carry on */ }

            return processed;
        }
Ejemplo n.º 3
0
 private void SetCellValue(ICell excelCell, COBieCell cell)
 {
     if (SetCellTypedValue(excelCell, cell) == false)
     {
         //check text length will fit in cell
         if (cell.CellValue.Length >= short.MaxValue)
         { 
             //truncate cell text to max length
             excelCell.SetCellValue(cell.CellValue.Substring(0, short.MaxValue - 1));
         }
         else
         {
             excelCell.SetCellValue(cell.CellValue);
         }
     }
 }
Ejemplo n.º 4
0
        private void FormatCell(ICell excelCell, COBieCell cell)
        {
            HSSFCellStyle style;
            if (_cellStyles.TryGetValue(cell.COBieColumn.AllowedType, out style))
            {
                excelCell.CellStyle = style;
            }

        }