Exemplo n.º 1
0
        private static void UpdateWorksheetReferencedFormulaCells(Worksheet worksheet, Cell fromCell,
                                                                  Stack <List <Cell> > dirtyCellStack = null)
        {
            List <Cell> dirtyCells = null;

            foreach (var range in worksheet.formulaRanges)
            {
                if (range.Value.Any(r => r.Contains(fromCell.InternalPos)))
                {
                    if ((dirtyCells == null || !dirtyCells.Contains(range.Key)) &&
                        (dirtyCellStack == null || dirtyCellStack.All(s => !s.Contains(range.Key))))
                    {
                        if (dirtyCells == null)
                        {
                            dirtyCells = new List <Cell>();
                        }

                        dirtyCells.Add(range.Key);
                    }
                }
            }

            if (dirtyCells != null && dirtyCells.Count > 0)
            {
                try
                {
                    if (dirtyCellStack == null)
                    {
                        dirtyCellStack = new Stack <List <Cell> >();
                    }

                    dirtyCellStack.Push(dirtyCells);

                    foreach (var dirtyCell in dirtyCells)
                    {
                        try
                        {
                            worksheet.RecalcCell(dirtyCell, dirtyCellStack);
                        }
                        catch (Exception ex)
                        {
                            worksheet.NotifyExceptionHappen(ex);
                        }
                    }
                }
                finally
                {
                    dirtyCellStack.Pop();
                }
            }
        }