Пример #1
0
 public Field(string name, Address address, Value.ValueType type = Value.ValueType.Text, Vocabulary vocabulary = null)
 {
     _name = name;
     _address = address;
     _type = type;
     _vocabulary = vocabulary;
 }
Пример #2
0
        protected override Value GetValue(int row, int col, Value.ValueType type = Value.ValueType.Text)
        {
            if (_worksheet == null)
                throw new CursorException("Worksheet is Null for Excel2003 Cursor");

            if (row <= 0 || col <= 0)
                throw new CursorException("Row and Column Indexes should be positive (>=1)");

            var cell = _worksheet.Cells[row-1, col-1];
            if (cell == null || cell.Value == null || cell.IsEmpty)
                return "";

            //var cellType = cell.Format.FormatType;

            if (type == Value.ValueType.Date)
            {
                return cell.DateTimeValue;
            }

            if (type == Value.ValueType.Number)
            {
                return Convert.ToDouble(cell.Value);
            }

            return cell.StringValue;
        }
Пример #3
0
        protected override Value GetValue(int row, int col, Value.ValueType type = Value.ValueType.Text)
        {
            if (_worksheet == null)
                throw new CursorException("Worksheet is Null for Excel2007 Cursor");

            if (row <= 0 || col <= 0)
                throw new CursorException("Row and Column Indexes should be positive (>=1)");

            var range = _worksheet.Cells[row, col];
            if (range == null || range.Value == null)
                return "";

            if (type == Value.ValueType.Date || range.Value is DateTime)
                return Convert.ToDateTime(range.Value);

            return range.Value.ToString();
        }
Пример #4
0
        public override Value GetValue(Address address, Value.ValueType type = Value.ValueType.Text)
        {
            if (address == null || String.IsNullOrEmpty(address.Uri))
                return "";

            var adr = address.Uri;

            //calculate column index or RC value
            int row = _row, col = 0;
            if (Int32.TryParse(adr, out col) || CursorExcel.ParseExcelAddress(adr, ref row, ref col))
                return this.GetValue(row, col, type);

            //calculate expression
            var expression = adr.StartsWith("=") ? adr.Substring(1) : adr;
            var calc = SXExpression.Calculate(expression, _environment);
            if (calc == null || calc.Value == null)
                throw new CursorException("Can't evaluate expression");

            return Value.Convert(calc.Value, type);

            //calculate expression
            //if (adr.StartsWith("=") && adr.Length > 1)
            //    return SXExpression.Calculate(adr.Substring(1), _environment);

            ////get '...' value
            //if (adr.Length >= 2 && adr.IndexOf('\'') == 0 && adr.IndexOf('\'', 1) == adr.Length - 1)
            //    return Value.Convert(adr.Substring(1, adr.Length - 2), type);

            ////get concatination ... + ... + ...
            //if (adr.Contains('+'))
            //{
            //    var parts = adr.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
            //    return Value.Convert(String.Join("", parts.Select(part => this.GetValue(part).ToString())), type);
            //}

            //throw new CursorException(String.Format("Excel Address not recognized: {0}", adr));
        }
Пример #5
0
 protected abstract Value GetValue(int row, int col, Value.ValueType type = Value.ValueType.Text);
Пример #6
0
        public static Value Convert(SXLexemValue value, Value.ValueType type)
        {
            if (value == null)
                throw new ArgumentException("Can't convert null LexemValue to Value");

            switch (type)
            {
                case Value.ValueType.Date:
                    {
                        if (value.Type == SXLexemValue.ValueType.Date)
                            return (value as SXLexemDate).Value;
                        if (value.Type == SXLexemValue.ValueType.Text)
                            return SXLexemDate.ParseDatetime((value as SXLexemText).Value);
                        break;
                    }
                case Value.ValueType.Number:
                    {
                        if (value.Type == SXLexemValue.ValueType.Number)
                            return (value as SXLexemNumber).Value;
                        if (value.Type == SXLexemValue.ValueType.Text)
                            return SXLexemNumber.ParseDouble((value as SXLexemText).Value, true);
                        break;
                    }
                default:
                    {
                        if (value.Type == SXLexemValue.ValueType.Text)
                            return (value as SXLexemText).Value;
                        if (value.Type == SXLexemValue.ValueType.Number)
                            return (value as SXLexemNumber).Value.ToString();
                        if (value.Type == SXLexemValue.ValueType.Date)
                            return (value as SXLexemDate).Value.ToString();
                        break;
                    }
            }

            throw new ReportGrabberException(String.Format("LexemValue {0} not recognized as Value", value.ToString()));
        }
Пример #7
0
        public static Value Convert(Value value, Value.ValueType type)
        {
            if (value == null)
                return null;

            if (value.Type == type)
                return value;

            switch (type)
            {
                case Value.ValueType.Number:
                    return SXLexemNumber.ParseDouble(value.ToString(), true);
                case Value.ValueType.Date:
                    return SXLexemDate.ParseDatetime(value.ToString());
                default:
                    return value.ToString();
            }
        }
Пример #8
0
 public Data(string name, Value value)
 {
     _name = name;
     _value = value;
 }
Пример #9
0
        /// <summary>
        /// Adds the Data to current collection
        /// </summary>
        /// <param name="name">Name of the new Data</param>
        /// <param name="value">Value of the new Data</param>
        /// <exception cref="ArgumentException">thrown when Name is empty or Data with such Name already exists in the collection</exception>
        public void Add(string name, Value value)
        {
            if (value == null)
                throw new ArgumentException("ReportData can't have null Value");

            if (String.IsNullOrEmpty(name))
                throw new ArgumentException("ReportData can't have empty Name");

            var item = this.Get(name);
            if (item != null)
                throw new ArgumentException(String.Format("ReportData with same name {0} already exists in current Collection"), name);

            _values.Add(new Data(name, value));
        }