Example #1
0
 public ParsingScope(ParsingScopes parsingScopes, ParsingScope parent, RangeAddress address)
 {
     _parsingScopes = parsingScopes;
     Parent = parent;
     Address = address;
     ScopeId = Guid.NewGuid();
 }
Example #2
0
 public virtual void AddReferenceTo(RangeAddress rangeAddress)
 {
     if (Address.CollidesWith(rangeAddress) || _referencedBy.Exists(x => x.CollidesWith(rangeAddress)))
     {
         throw new CircularReferenceException("Circular reference detected at " + rangeAddress.ToString());
     }
     _references.Add(rangeAddress);
 }
Example #3
0
 /// <summary>
 /// Creates a new <see cref="ParsingScope"/> and puts it on top of the stack.
 /// </summary>
 /// <param name="address"></param>
 /// <returns></returns>
 public virtual ParsingScope NewScope(RangeAddress address)
 {
     ParsingScope scope;
     if (_scopes.Count() > 0)
     {
         scope = new ParsingScope(this, _scopes.Peek(), address);
     }
     else
     {
         scope = new ParsingScope(this, address);
     }
     _scopes.Push(scope);
     return scope;
 }
Example #4
0
 /// <summary>
 /// Returns true if this range collides (full or partly) with the supplied range
 /// </summary>
 /// <param name="other">The range to check</param>
 /// <returns></returns>
 public bool CollidesWith(RangeAddress other)
 {
     if (other.Worksheet != Worksheet)
     {
         return false;
     }
     if (other.FromRow > ToRow || other.FromCol > ToCol
         ||
         FromRow > other.ToRow || FromCol > other.ToCol)
     {
         return false;
     }
     return true;
 }
Example #5
0
 private void Initialize()
 {
     _index = 0;
     var factory = new RangeAddressFactory(ParsingContext.ExcelDataProvider);
     if (Arguments.RangeInfo == null)
     {
         _rangeAddress = factory.Create(ParsingContext.Scopes.Current.Address.Worksheet, Arguments.RangeAddress);
     }
     else
     {
         _rangeAddress = factory.Create(Arguments.RangeInfo.Address.WorkSheet, Arguments.RangeInfo.Address.Address);
     }
     _currentCol = _rangeAddress.FromCol;
     _currentRow = _rangeAddress.FromRow;
     SetCurrentValue();
 }
Example #6
0
 protected LookupDirection GetLookupDirection(RangeAddress rangeAddress)
 {
     var nRows = rangeAddress.ToRow - rangeAddress.FromRow;
     var nCols = rangeAddress.ToCol - rangeAddress.FromCol;
     return nCols > nRows ? LookupDirection.Horizontal : LookupDirection.Vertical;
 }
Example #7
0
 private void HandleSingleCellAddress(RangeAddress rangeAddress, ExcelAddressInfo addressInfo)
 {
     int col, row;
     _addressTranslator.ToColAndRow(addressInfo.StartCell, out col, out row);
     rangeAddress.FromCol = col;
     rangeAddress.ToCol = col;
     rangeAddress.FromRow = row;
     rangeAddress.ToRow = row;
 }
Example #8
0
 private void HandleMultipleCellAddress(RangeAddress rangeAddress, ExcelAddressInfo addressInfo)
 {
     int fromCol, fromRow;
     _addressTranslator.ToColAndRow(addressInfo.StartCell, out fromCol, out fromRow);
     int toCol, toRow;
     _addressTranslator.ToColAndRow(addressInfo.EndCell, out toCol, out toRow, AddressTranslator.RangeCalculationBehaviour.LastPart);
     rangeAddress.FromCol = fromCol;
     rangeAddress.ToCol = toCol;
     rangeAddress.FromRow = fromRow;
     rangeAddress.ToRow = toRow;
 }
Example #9
0
        public RangeAddress Create(string range)
        {
            Require.That(range).Named("range").IsNotNullOrEmpty();
            //var addressInfo = ExcelAddressInfo.Parse(range);
            var adr = new ExcelAddressBase(range);
            var rangeAddress = new RangeAddress()
            {
                Address = adr.Address,
                Worksheet = adr.WorkSheet ?? "",
                FromRow = adr._fromRow,
                FromCol = adr._fromCol,
                ToRow = adr._toRow,
                ToCol = adr._toCol
            };

            //if (addressInfo.IsMultipleCells)
            //{
            //    HandleMultipleCellAddress(rangeAddress, addressInfo);
            //}
            //else
            //{
            //    HandleSingleCellAddress(rangeAddress, addressInfo);
            //}
            return rangeAddress;
        }
Example #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="worksheetName">will be used if no worksheet name is specified in <paramref name="address"/></param>
        /// <param name="address">address of a range</param>
        /// <returns></returns>
        public RangeAddress Create(string worksheetName, string address)
        {
            Require.That(address).Named("range").IsNotNullOrEmpty();
            //var addressInfo = ExcelAddressInfo.Parse(address);
            var adr = new ExcelAddressBase(address);  
            var sheet = string.IsNullOrEmpty(adr.WorkSheet) ? worksheetName : adr.WorkSheet;
            var dim = _excelDataProvider.GetDimensionEnd(adr.WorkSheet);
            var rangeAddress = new RangeAddress()
            {
                Address = adr.Address,
                Worksheet = sheet,
                FromRow = adr._fromRow,
                FromCol = adr._fromCol,
                ToRow = (dim != null && adr._toRow > dim.Row) ? dim.Row : adr._toRow,
                ToCol = adr._toCol
            };

            //if (addressInfo.IsMultipleCells)
            //{
            //    HandleMultipleCellAddress(rangeAddress, addressInfo);
            //}
            //else
            //{
            //    HandleSingleCellAddress(rangeAddress, addressInfo);
            //}
            return rangeAddress;
        }
Example #11
0
 public ParsingScope(ParsingScopes parsingScopes, RangeAddress address)
     : this(parsingScopes, null, address)
 {
 }
Example #12
0
 internal virtual object Parse(string formula, RangeAddress rangeAddress)
 {
     using (var scope = _parsingContext.Scopes.NewScope(rangeAddress))
     {
         var tokens = _lexer.Tokenize(formula);
         var graph = _graphBuilder.Build(tokens);
         if (graph.Expressions.Count() == 0)
         {
             return null;
         }
         return _compiler.Compile(graph.Expressions).Result;
     }
 }