Esempio n. 1
0
        private CollaboratingWorkbooksEnvironment(Dictionary <string, WorkbookEvaluator> evaluatorsByName, WorkbookEvaluator[] evaluators)
        {
            Dictionary <WorkbookEvaluator, string> uniqueEvals = new Dictionary <WorkbookEvaluator, string>(evaluators.Length);

            foreach (string wbName in evaluatorsByName.Keys)
            {
                WorkbookEvaluator wbEval = evaluatorsByName[(wbName)];
                if (uniqueEvals.ContainsKey(wbEval))
                {
                    string msg = "Attempted to register same workbook under names '"
                                 + uniqueEvals[(wbEval)] + "' and '" + wbName + "'";
                    throw new ArgumentException(msg);
                }
                uniqueEvals.Add(wbEval, wbName);
            }
            UnhookOldEnvironments(evaluators);
            HookNewEnvironment(evaluators, this);
            _unhooked         = false;
            _evaluators       = evaluators;
            _evaluatorsByName = evaluatorsByName;
        }
Esempio n. 2
0
        public void NotifyUpdateCell(int bookIndex, int sheetIndex, IEvaluationCell cell)
        {
            FormulaCellCacheEntry fcce = _formulaCellCache.Get(cell);

            int rowIndex    = cell.RowIndex;
            int columnIndex = cell.ColumnIndex;
            Loc loc         = new Loc(bookIndex, sheetIndex, cell.RowIndex, cell.ColumnIndex);
            PlainValueCellCacheEntry pcce = _plainCellCache.Get(loc);

            if (cell.CellType == Npoi.Core.SS.UserModel.CellType.Formula)
            {
                if (fcce == null)
                {
                    fcce = new FormulaCellCacheEntry();

                    if (pcce == null)
                    {
                        if (_evaluationListener != null)
                        {
                            _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                                                       columnIndex, cell, fcce);
                        }
                        UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                    }
                    _formulaCellCache.Put(cell, fcce);
                }
                else
                {
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    fcce.ClearFormulaEntry();
                }
                if (pcce == null)
                {
                    // was formula cell before - no Change of type
                }
                else
                {
                    // changing from plain cell To formula cell
                    pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    _plainCellCache.Remove(loc);
                }
            }
            else
            {
                ValueEval value = WorkbookEvaluator.GetValueFromNonFormulaCell(cell);
                if (pcce == null)
                {
                    if (value != BlankEval.instance)
                    {
                        pcce = new PlainValueCellCacheEntry(value);
                        if (fcce == null)
                        {
                            if (_evaluationListener != null)
                            {
                                _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                                                           columnIndex, cell, pcce);
                            }
                            UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                        }
                        _plainCellCache.Put(loc, pcce);
                    }
                }
                else
                {
                    if (pcce.UpdateValue(value))
                    {
                        pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    }
                    if (value == BlankEval.instance)
                    {
                        _plainCellCache.Remove(loc);
                    }
                }
                if (fcce == null)
                {
                    // was plain cell before - no Change of type
                }
                else
                {
                    // was formula cell before - now a plain value
                    _formulaCellCache.Remove(cell);
                    fcce.SetSensitiveInputCells(null);
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                }
            }
        }