Пример #1
0
 public CalcRelation AddRelationTo(CalcCell other, CalcChain chain)
 {
     if (_relationsTo.ContainsKey(other.Id)) return _relationsTo[other.Id];
     var rel = new CalcRelation { CalcCellId = other.Id, CalcChainId = chain.Id };
     _relationsTo.Add(other.Id, rel);
     return rel;
 }
        public CalcChainContext Build(ParsingContext context, string worksheetName)
        {
            _parsingContext = context;
            var chainContext = CalcChainContext.Create(context.Configuration.IdProvider);
            var lexer        = context.Configuration.Lexer;
            var cells        = string.IsNullOrEmpty(worksheetName) ?
                               _parsingContext.ExcelDataProvider.GetWorkbookFormulas() :
                               _parsingContext.ExcelDataProvider.GetWorksheetFormulas(worksheetName);

            foreach (var cellInfo in cells)
            {
                var address     = cellInfo.Key;
                var cell        = chainContext.CalcCells.AddOrGet(address);
                var formula     = cellInfo.Value;
                var r           = lexer.Tokenize(formula);
                var toAddresses = r.Where(x => x.TokenType == TokenType.ExcelAddress);
                foreach (var toAddress in toAddresses)
                {
                    var rangeAddress = context.RangeAddressFactory.Create(toAddress.Value);
                    var rangeCells   = new List <string>();
                    if (rangeAddress.FromRow < rangeAddress.ToRow || rangeAddress.FromCol < rangeAddress.ToCol)
                    {
                        for (var col = rangeAddress.FromCol; col <= rangeAddress.ToCol; col++)
                        {
                            for (var row = rangeAddress.FromRow; row <= rangeAddress.ToRow; row++)
                            {
                                rangeCells.Add(context.RangeAddressFactory.Create(col + 1, row + 1).Address);
                            }
                        }
                    }
                    else
                    {
                        rangeCells.Add(toAddress.Value);
                    }
                    CalcChain chain;
                    foreach (var rangeCell in rangeCells)
                    {
                        var toCell  = chainContext.CalcCells.AddOrGet(rangeCell);
                        var chainId = cell.GetCalcChainId();
                        if (chainId == null)
                        {
                            chain = CalcChain.Create(context.Configuration.IdProvider);
                            chainContext.AddCalcChain(chain);
                        }
                        else
                        {
                            chain = chainContext.CalcChains.Where(x => x.Id == chainId).FirstOrDefault();
                        }
                        chain.Add(toCell);
                        cell.AddRelationTo(toCell, chain);
                        toCell.AddRelationFrom(cell, chain);
                    }
                }
            }

            return(chainContext);
        }
Пример #3
0
        public CalcRelation AddRelationFrom(CalcCell other, CalcChain chain)
        {
            if (_relationsFrom.ContainsKey(other.Id))
            {
                return(_relationsFrom[other.Id]);
            }
            var rel = new CalcRelation {
                CalcCellId = other.Id, CalcChainId = chain.Id
            };

            _relationsFrom.Add(other.Id, rel);
            return(rel);
        }
Пример #4
0
        public object GetCalcChainId()
        {
            CalcChain resultChain = null;

            foreach (var rel in _relationsFrom)
            {
                var chain = _context.GetCalcChain(rel.Value.CalcChainId);
                if (resultChain == null || chain.Count > resultChain.Count)
                {
                    resultChain = chain;
                }
            }
            return(resultChain != null ? resultChain.Id : null);
        }
 public virtual void AddCalcChain(CalcChain chain)
 {
     _calcChains.Add(chain.Id, chain);
 }
Пример #6
0
 public void Setup()
 {
     _chainContext = CalcChainContext.Create(new IntegerIdProvider());
     _chain = CalcChain.Create(_chainContext.IdProvider);
 }
Пример #7
0
 public virtual void AddCalcChain(CalcChain chain)
 {
     _calcChains.Add(chain.Id, chain);
 }