예제 #1
0
        internal void ResumeCalcGraph()
        {
            Exception      exception = null;
            CalcExpression expr      = null;

            foreach (KeyValuePair <CalcLocalIdentity, Tuple <CalcExpression, bool> > pair in this._tmpFormulas)
            {
                CalcLocalIdentity key = pair.Key;
                expr = pair.Value.Item1;
                try
                {
                    this.Graph.SetNode(key, expr, this.Source.GetEvaluatorContext(key), this.Source, pair.Value.Item2);
                    this._formulas[key] = expr;
                }
                catch (Exception exception2)
                {
                    if (exception == null)
                    {
                        exception = exception2;
                    }
                }
            }
            this._tmpFormulas.Clear();
            if (exception != null)
            {
                throw exception;
            }
        }
예제 #2
0
        protected virtual CalcExpression VisitFunctionExpression(CalcFunctionExpression expr, int baseRow, int baseColumn)
        {
            int argCount = expr.ArgCount;

            CalcExpression[] args = new CalcExpression[argCount];
            bool             flag = false;

            for (int i = 0; i < argCount; i++)
            {
                CalcExpression arg = expr.GetArg(i);
                args[i] = this.Visit(arg, baseRow, baseColumn);
                if (arg != args[i])
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                return(expr);
            }
            if (object.ReferenceEquals(expr.Function, null))
            {
                return(new CalcFunctionExpression(expr.FunctionName, args));
            }
            return(new CalcFunctionExpression(expr.Function, args));
        }
예제 #3
0
        public static CellRange ParseCellRange(Worksheet worksheet, string cellRange)
        {
            CalcExpression expression = FormulaUtility.Formula2Expression(worksheet, cellRange);

            if (expression is CalcReferenceExpression)
            {
                return(GetRangeFromExpression(expression as CalcReferenceExpression));
            }
            if (expression is CalcNameExpression)
            {
                CalcNameExpression expression2 = expression as CalcNameExpression;
                NameInfo           customName  = worksheet.GetCustomName(expression2.Name);
                if ((customName != null) && (customName.Expression is CalcReferenceExpression))
                {
                    return(GetRangeFromExpression(customName.Expression as CalcReferenceExpression));
                }
            }
            else if (expression is CalcExternalNameExpression)
            {
                CalcExternalNameExpression expression3 = expression as CalcExternalNameExpression;
                NameInfo info2 = worksheet.GetCustomName(expression3.Name);
                if ((info2 != null) && (info2.Expression is CalcReferenceExpression))
                {
                    return(GetRangeFromExpression(info2.Expression as CalcReferenceExpression));
                }
            }
            return(null);
        }
예제 #4
0
        static CalcExpression AddRowRange(int row, int rowCount, CalcExpression dataRange)
        {
            CalcRangeExpression expression = dataRange as CalcRangeExpression;

            if (expression != null)
            {
                if (row > expression.EndRow)
                {
                    return(expression);
                }
                if (row > expression.StartRow)
                {
                    return(expression.Offset(0, 0, rowCount, 0, true, true));
                }
                return(expression.Offset(rowCount, 0, true, true) as CalcRangeExpression);
            }
            CalcExternalRangeExpression expression2 = dataRange as CalcExternalRangeExpression;

            if (expression2 == null)
            {
                return(null);
            }
            if (row > expression2.EndRow)
            {
                return(expression2);
            }
            if (row > expression2.StartRow)
            {
                return(expression2.Offset(0, 0, rowCount, 0, true, true));
            }
            return(expression2.Offset(rowCount, 0, true, true) as CalcExternalRangeExpression);
        }
예제 #5
0
        public void OffsetFormulasWhileCopy(Worksheet src, int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount, Dictionary <Tuple <int, int>, DataValidator> copiedValidators)
        {
            DataValidationConditionalGraph graph = null;

            rowCount    = (rowCount <= 0) ? 0 : rowCount;
            columnCount = (columnCount <= 0) ? 0 : columnCount;
            int num = toRow - fromRow;

            foreach (KeyValuePair <Tuple <int, int>, DataValidator> pair in copiedValidators)
            {
                int                   rowOffset         = num + (((pair.Key.Item1 - toRow) / rowCount) * rowCount);
                int                   columnOffset      = num + (((pair.Key.Item2 - toColumn) / columnCount) * columnCount);
                MoveVisitor           visitor           = new MoveVisitor(new CellRange(fromRow, fromColumn, rowCount, columnCount), rowOffset, columnOffset, graph._sheetRowCount, graph._sheetColumnCount, false, null, false, null, true);
                IConditionalFormula[] formulaConditions = pair.Value.FormulaConditions;
                if ((formulaConditions != null) && (formulaConditions.Length != 0))
                {
                    foreach (IConditionalFormula formula in formulaConditions)
                    {
                        CalcExpression expr = graph.Formula2Expression(formula.Formula, toRow, toColumn);
                        expr            = visitor.Visit(expr, toRow, toColumn);
                        formula.Formula = graph.Expression2Formula(expr, toRow, toColumn);
                    }
                }
            }
        }
예제 #6
0
        public void Swap(int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount)
        {
            Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > dictionary  = this.GetAllFromulas(fromRow, fromColumn, rowCount, columnCount);
            Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > dictionary2 = this.GetAllFromulas(toRow, toColumn, rowCount, columnCount);
            int rowOffset    = toRow - fromRow;
            int columnOffset = toColumn - fromColumn;

            this.Clear(fromRow, fromColumn, rowCount, columnCount);
            this.Clear(toRow, toColumn, rowCount, columnCount);
            MoveVisitor visitor = new MoveVisitor(new CellRange(fromRow, fromColumn, rowCount, columnCount), rowOffset, columnOffset, this._sheetRowCount, this._sheetColumnCount, false, null, false, null, false);

            using (Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > .ValueCollection.Enumerator enumerator = dictionary.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    foreach (ConditionalGraph.ConditionalIdentity identity in enumerator.Current)
                    {
                        CalcExpression expr = visitor.Visit(identity.Expression, toRow, toColumn);
                        ((IFormulaOperatorSource)this).SetExpression(identity, expr);
                    }
                }
            }
            visitor = new MoveVisitor(new CellRange(toRow, toColumn, rowCount, columnCount), -rowOffset, -columnOffset, this._sheetRowCount, this._sheetColumnCount, false, null, false, null, true);
            using (Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > .ValueCollection.Enumerator enumerator3 = dictionary2.Values.GetEnumerator())
            {
                while (enumerator3.MoveNext())
                {
                    foreach (ConditionalGraph.ConditionalIdentity identity2 in enumerator3.Current)
                    {
                        CalcExpression expression2 = visitor.Visit(identity2.Expression, fromRow, fromColumn);
                        ((IFormulaOperatorSource)this).SetExpression(identity2, expression2);
                    }
                }
            }
        }
예제 #7
0
 private object EvaluateBinaryOperation(CalcBinaryOperatorExpression expr, CalcEvaluatorContext context, bool acceptsArray)
 {
     CalcExpression[] expressionArray = new CalcExpression[] { expr.Left, expr.Right };
     object[]         objArray        = new object[2];
     for (int i = 0; i < 2; i++)
     {
         object obj2 = this.Evaluate(expressionArray[i], context, acceptsArray, expr.Operator.AcceptsReference(i));
         if (obj2 is CalcError)
         {
             return(obj2);
         }
         if (obj2 is CalcMissingArgument)
         {
             return(CalcErrors.NotAvailable);
         }
         objArray[i] = obj2;
     }
     try
     {
         return(expr.Operator.Evaluate(objArray[0], objArray[1], context));
     }
     catch (InvalidCastException)
     {
         return(CalcErrors.Value);
     }
 }
예제 #8
0
        void MoveDataRange(int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount)
        {
            CellRange range  = new CellRange(fromRow, fromColumn, rowCount, columnCount);
            int       row    = toRow - fromRow;
            int       column = toColumn - fromColumn;

            using (List <SparklineGroup> .Enumerator enumerator = this.Groups.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    foreach (Sparkline sparkline in enumerator.Current)
                    {
                        if (sparkline != null)
                        {
                            CalcExpression dateAxisReference = sparkline.DateAxisReference;
                            CellRange      expressionRange   = GetExpressionRange(dateAxisReference);
                            if (((expressionRange != null) && SameSource((ICalcSource)this.Sheet, dateAxisReference)) && (range.Contains(expressionRange) && range.Contains(sparkline.Row, sparkline.Column)))
                            {
                                sparkline.DateAxisReference = dateAxisReference.Offset(row, column, false, true);
                            }
                            CalcExpression dataReference = sparkline.DataReference;
                            CellRange      range3        = GetExpressionRange(dataReference);
                            if (((range3 != null) && SameSource(this.Sheet as ICalcSource, dataReference)) && (range.Contains(range3) && range.Contains(sparkline.Row, sparkline.Column)))
                            {
                                sparkline.DataReference = dataReference.Offset(row, column, false, true);
                            }
                        }
                    }
                }
            }
        }
예제 #9
0
        static CalcExpression RemoveRowRange(int row, int rowCount, CalcExpression dataRange)
        {
            int targetEnd = (row + rowCount) - 1;
            CalcRangeExpression expression = dataRange as CalcRangeExpression;

            if (expression != null)
            {
                int resultStart = -1;
                int resultEnd   = -1;
                SubCat(expression.StartRow, expression.EndRow, row, targetEnd, ref resultStart, ref resultEnd);
                if ((resultStart > -1) && (resultEnd > -1))
                {
                    return(expression.Offset(resultStart - expression.StartRow, 0, resultEnd - expression.EndRow, 0, true, true));
                }
            }
            else
            {
                CalcExternalRangeExpression expression2 = dataRange as CalcExternalRangeExpression;
                if (expression2 != null)
                {
                    int num4 = -1;
                    int num5 = -1;
                    SubCat(expression2.StartRow, expression2.EndRow, row, targetEnd, ref num4, ref num5);
                    if ((num4 > -1) && (num5 > -1))
                    {
                        return(expression2.Offset(num4 - expression2.StartRow, 0, num5 - expression2.EndRow, 0, true, true));
                    }
                }
            }
            return(null);
        }
예제 #10
0
 static bool ContainsOrEqual(CalcCalculationManager mgr, CalcLocalIdentity id1, CalcLocalIdentity id2)
 {
     CalcLocalIdentityExtension.CompareResult result;
     CalcLocalIdentityExtension.CompareResult result2;
     if (id2.TryCompareTo(id1, out result, out result2))
     {
         CalcNode       objA       = mgr.Graph.GetNode(id2);
         CalcExpression expression = mgr.GetExpression(id2);
         if (expression == null)
         {
             return(false);
         }
         if ((!object.ReferenceEquals(objA, null) && (objA.OwnerNode != null)) && (expression is CalcSharedExpression))
         {
             return(false);
         }
         if (((id2 is CalcRangeIdentity) && (((result == CalcLocalIdentityExtension.CompareResult.Great_Intersected) || (result == CalcLocalIdentityExtension.CompareResult.Less_Intersected)) || (result == CalcLocalIdentityExtension.CompareResult.Contains))) && (((result2 == CalcLocalIdentityExtension.CompareResult.Great_Intersected) || (result2 == CalcLocalIdentityExtension.CompareResult.Less_Intersected)) || (result2 == CalcLocalIdentityExtension.CompareResult.Contains)))
         {
             if (!(mgr.GetExpression(id2) is CalcSharedExpression))
             {
                 throw new InvalidOperationException(ResourceStrings.FormulaChangePartOfArrayFormulaError);
             }
             return(false);
         }
         if (((result == CalcLocalIdentityExtension.CompareResult.Contained) || (result == CalcLocalIdentityExtension.CompareResult.Equal)) && ((result2 == CalcLocalIdentityExtension.CompareResult.Contained) || (result2 == CalcLocalIdentityExtension.CompareResult.Equal)))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #11
0
 public void Sort(IDictionary <int, int> movedRows)
 {
     if (movedRows.Count != 0)
     {
         ChangingContext context = new ChangingContext();
         foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in this.Storage)
         {
             CalcCellIdentity identity = pair.Key as CalcCellIdentity;
             if (identity != null)
             {
                 int num2;
                 int rowIndex = identity.RowIndex;
                 if (movedRows.TryGetValue(rowIndex, out num2))
                 {
                     if (!context.ChangedFormulas.ContainsKey(identity))
                     {
                         context.ChangedFormulas[identity] = null;
                     }
                     if (num2 >= 0)
                     {
                         CalcCellIdentity identity2 = new CalcCellIdentity(num2, identity.ColumnIndex);
                         CalcExpression   expr      = pair.Value;
                         int?maxColCount            = null;
                         expr = new ReferenceValidateVisitor(new int?(this.RowCount - 1), maxColCount).Visit(expr, num2, identity.ColumnIndex);
                         context.ChangedFormulas[identity2] = new Tuple <CalcLocalIdentity, CalcExpression>(identity, expr);
                     }
                 }
             }
         }
         FormulaOperatorHelper.UpdataChangings(this._formulaOperatorSource, context);
     }
 }
예제 #12
0
        public void Add(CalcExpression e)
        {
            //if (e is IEnumerable ienum)
            //{
            //    foreach (var value in ienum)
            //    {
            //        AddValue(value);
            //    }
            //    return;
            //}

            //AddValue(e.Evaluate());

            var r = e.Evaluate();

            if (r is IEnumerable && !(r is string))
            {
                var ienum = r as IEnumerable;

                foreach (var value in ienum)
                {
                    AddValue(value);
                }
                return;
            }

            AddValue(r);
        }
예제 #13
0
        public CalcExpression this[string expression]
        {
            get
            {
                CalcExpression x = null;
                WeakReference  wr;

                if (_dct.TryGetValue(expression, out wr))
                {
                    x = wr.Target as CalcExpression;
                }

                if (x == null)
                {
                    if (_dct.Count > 100 && _hitCount++ > 100)
                    {
                        RemoveDeadReferences();
                        _hitCount = 0;
                    }

                    x = _ce.Parse(expression);
                    _dct[expression] = new WeakReference(x);
                }

                return(x);
            }
        }
예제 #14
0
        /// <summary>
        /// 判断是输入字符串为计算表达式
        /// </summary>
        /// <returns></returns>
        private bool stringJudge(string str)
        {
            bool flag = false;

            try
            {
                //是否为计算表达式(20*98-7/0.23)
                //string reg = @"^([-]?\d{1,}\.?[-]?\d{0,}[\.,\+,\-,\*,\/][-]?\d{1,}\.?[-]?\d{0,})+$";
                //flag = str.isMatch(reg);
                //flag = str.IndexOfAny(new char[4] { '+', '-', '*', '/' }) > -1;
                flag = CalcExpression.HasOperator(str);
                if (flag)
                {
                    string res = calc(str);
                    Clipboard.SetDataObject(res);
                    MessageBox.Show(res);
                    this.txtContent.Focus();
                }
            }
            catch (Exception)
            {
                flag = false;
            }
            return(flag);
        }
예제 #15
0
        public static SheetCellRange[] ValidateFormula(ICalcEvaluator evaluator, string formula, bool acceptConstantExpression = false)
        {
            if (string.IsNullOrEmpty(formula) || (evaluator == null))
            {
                return(null);
            }
            CalcExpression expression = FormulaUtility.Formula2Expression(evaluator, formula);

            if (expression == null)
            {
                throw new ArgumentException("Formula is invalid.");
            }
            if ((expression is CalcConstantExpression) && acceptConstantExpression)
            {
                return(null);
            }
            SheetCellRange[] rangeArray = SheetCellRangeUtility.ExtractAllExternalReference(evaluator, formula);
            if (rangeArray == null)
            {
                throw new ArgumentException("Formula is invalid.");
            }
            if (rangeArray.Length > 0)
            {
                Worksheet sheet = null;
                foreach (SheetCellRange range in rangeArray)
                {
                    if ((sheet != null) && (range.Sheet != sheet))
                    {
                        throw new ArgumentException("Formula is invalid.");
                    }
                    sheet = range.Sheet;
                }
            }
            return(rangeArray);
        }
예제 #16
0
 public void AddRows(int row, int count)
 {
     foreach (SparklineGroup group in this.Groups)
     {
         if (group.DisplayDateAxis)
         {
             CalcExpression expression = AddRowRange(row, count, group.DateAxisReference);
             if (expression != group.DateAxisReference)
             {
                 group.DateAxisReference = expression;
             }
         }
         foreach (Sparkline sparkline in group)
         {
             if (row <= sparkline.Row)
             {
                 sparkline.Row += count;
             }
             CalcExpression expression2 = AddRowRange(row, count, sparkline.DataReference);
             if (expression2 != sparkline.DataReference)
             {
                 sparkline.DataReference = expression2;
             }
         }
     }
 }
예제 #17
0
 public static SheetCellRange ExtractRange(ICalcEvaluator sheet, CalcExpression value)
 {
     if ((value != null) && !(value is CalcConstantExpression))
     {
         if ((value is CalcExternalCellExpression) || (value is CalcExternalRangeExpression))
         {
             CalcExternalCellExpression expression = value as CalcExternalCellExpression;
             if (expression != null)
             {
                 return(new SheetCellRange(expression.Source as Worksheet, expression.Row, expression.Column, 1, 1));
             }
             CalcExternalRangeExpression expression2 = value as CalcExternalRangeExpression;
             if (expression2 != null)
             {
                 return(new SheetCellRange(expression2.Source as Worksheet, expression2.StartRow, expression2.StartColumn, (expression2.EndRow - expression2.StartRow) + 1, (expression2.EndColumn - expression2.StartColumn) + 1));
             }
         }
         else if (value is CalcExternalNameExpression)
         {
             SheetCellRange[] rangeArray = SheetCellRangeUtility.ExtractAllExternalReference(sheet, value);
             if ((rangeArray != null) && (rangeArray.Length > 0))
             {
                 return(rangeArray[0]);
             }
         }
     }
     return(null);
 }
예제 #18
0
        public static string StringVariantToInvariant(Worksheet worksheet, string variantString)
        {
            if (worksheet == null)
            {
                return(variantString);
            }
            bool   flag  = worksheet.ReferenceStyle == ReferenceStyle.A1;
            string str   = variantString;
            bool   flag2 = (str != null) && str.StartsWith("=");

            try
            {
                CalcParser     parser = new CalcParser();
                CalcExpression expr   = parser.Parse(variantString, new SpreadCalcParserContext(worksheet, !flag, 0, 0, CultureInfo.CurrentCulture));
                str = parser.Unparse(expr, new SpreadCalcParserContext(worksheet, !flag, 0, 0, CultureInfo.InvariantCulture));
                if (flag2)
                {
                    variantString = "=" + variantString;
                }
            }
            catch
            {
            }
            return(str);
        }
예제 #19
0
        public static void ExtractAllReferenceExpression(ICalcEvaluator evaluator, CalcExpression expression, out CalcReferenceExpression[] expressions)
        {
            List <CalcReferenceExpression> nodes = new List <CalcReferenceExpression>();

            ExtractAllReferenceExpression(evaluator, expression, nodes);
            expressions = nodes.ToArray();
        }
예제 #20
0
        static CalcExpression AddColumnRange(int column, int columnCount, CalcExpression dataRange)
        {
            CalcRangeExpression expression = dataRange as CalcRangeExpression;

            if (expression != null)
            {
                if (column > expression.EndColumn)
                {
                    return(expression);
                }
                if (column > expression.StartColumn)
                {
                    return(expression.Offset(0, 0, 0, columnCount, true, true));
                }
                return(expression.Offset(0, columnCount, true, true) as CalcRangeExpression);
            }
            CalcExternalRangeExpression expression2 = dataRange as CalcExternalRangeExpression;

            if (expression2 == null)
            {
                return(null);
            }
            if (column > expression2.EndColumn)
            {
                return(expression2);
            }
            if (column > expression2.StartColumn)
            {
                return(expression2.Offset(0, 0, 0, columnCount, true, true));
            }
            return(expression2.Offset(0, columnCount, true, true) as CalcExternalRangeExpression);
        }
예제 #21
0
 /// <summary>
 /// Constructs a new custom named expression.
 /// </summary>
 /// <param name="name">The name of the custom named expression.</param>
 /// <param name="baseRow">The base row index of the custom named expression.</param>
 /// <param name="baseColumn">The base column index of the custom named expression.</param>
 /// <param name="expression">The calculate expression that is used to customize the named expression.</param>
 public NameInfo(string name, int baseRow, int baseColumn, CalcExpression expression)
 {
     this.name       = name;
     this.baseRow    = baseRow;
     this.baseColumn = baseColumn;
     this.expression = expression;
 }
예제 #22
0
 static bool SameSource(ICalcSource source, CalcExpression exp)
 {
     if (exp is CalcExternalExpression)
     {
         return(source == ((CalcExternalExpression)exp).Source);
     }
     return(true);
 }
예제 #23
0
 public DefaultDataSeries(CalcExpression dataReference, Dt.Cells.Data.DataOrientation dataOrientation, bool displayHiddenData, Dt.Cells.Data.EmptyValueStyle emptyValueStyle, ICalcEvaluator evalutor)
 {
     this._dataReference     = dataReference;
     this._dataOrientation   = new Dt.Cells.Data.DataOrientation?(dataOrientation);
     this._displayHiddenData = displayHiddenData;
     this._emptyValueStyle   = emptyValueStyle;
     this._evaluator         = evalutor;
 }
예제 #24
0
        public void TestInitialize(string name, DriverType driverType, CalcExpression expression)
        {
            IWebDriver driver = CreateDriver(driverType);

            driver.Manage().Cookies.DeleteAllCookies();
            driver.Manage().Window.Maximize();
            TestPropertiesStorage.Instance.Add(TestContext.CurrentContext.Test.ID, new TestProperties(name, driver, expression));
        }
예제 #25
0
        public void RemoveSheet(IList sources, ICalcSource replacedSource)
        {
            ICalcSource currentSource = this.Manager.Source;
            Dictionary <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> > dictionary = new Dictionary <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> >();

            foreach (object obj2 in sources)
            {
                ICalcSource source = obj2 as ICalcSource;
                if (source != null)
                {
                    CalcCalculationManager manager = this.Manager.Service.GetCalculationManager(source, null, true);
                    if (manager != null)
                    {
                        foreach (CalcLocalIdentity identity in manager.Graph.GetAllSheetRangeIdentities())
                        {
                            CalcNode node = manager.Graph.GetNode(identity);
                            if (node.Precedents != null)
                            {
                                using (List <CalcNode> .Enumerator enumerator3 = node.Precedents.GetEnumerator())
                                {
                                    while (enumerator3.MoveNext())
                                    {
                                        if (enumerator3.Current.Source == currentSource)
                                        {
                                            Dictionary <CalcLocalIdentity, CalcExpression> dictionary2;
                                            if (!dictionary.TryGetValue(manager, out dictionary2))
                                            {
                                                dictionary2         = new Dictionary <CalcLocalIdentity, CalcExpression>();
                                                dictionary[manager] = dictionary2;
                                            }
                                            dictionary2[identity] = manager.GetExpression(identity);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            RemoveSheetVisitor visitor = new RemoveSheetVisitor(currentSource, replacedSource);

            foreach (KeyValuePair <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> > pair in dictionary)
            {
                CalcCalculationManager mgr = pair.Key;
                foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair2 in pair.Value)
                {
                    int num;
                    int num2;
                    int num3;
                    int num4;
                    mgr.ClearExpression(pair2.Key);
                    FormulaOperatorHelper.Identity2Indexs(pair2.Key, out num, out num2, out num3, out num4);
                    CalcExpression expr = visitor.Visit(pair2.Value, num, num2);
                    CalcExpressionHelper.SetExpression(mgr, pair2.Key, expr, true);
                    mgr.Invalidate(pair2.Key, false);
                }
            }
        }
예제 #26
0
        public static void Save(CalcCalculationManager sourceMgr, CalcCalculationManager targetMgr, ChangingContext context, int sourceRowCount, int sourceColumnCount, int fromRow, int fromColumn, int toRow, int toColumn, int fromRowCount, int fromColumnCount, int toRowCount, int toColumnCount, Dictionary <CalcLocalIdentity, CalcExpression> formulas, bool offsetSelf, bool updataDependens)
        {
            Dictionary <CalcLocalIdentity, CalcExpression> dictionary3;

            if (context == null)
            {
                context = new ChangingContext();
            }
            GetDependentsFromulas(sourceMgr, targetMgr, context, fromRow, fromColumn, toRow, toColumn, fromRowCount, formulas, fromColumnCount, offsetSelf, updataDependens);
            Dictionary <CalcCellIdentity, CalcExpression>  cellFormulas  = new Dictionary <CalcCellIdentity, CalcExpression>();
            Dictionary <CalcRangeIdentity, CalcExpression> rangeFormulas = new Dictionary <CalcRangeIdentity, CalcExpression>();

            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in formulas)
            {
                if (pair.Key is CalcCellIdentity)
                {
                    cellFormulas[pair.Key as CalcCellIdentity] = pair.Value;
                }
                else if (pair.Key is CalcRangeIdentity)
                {
                    rangeFormulas[pair.Key as CalcRangeIdentity] = pair.Value;
                }
            }
            GetTargetFormulas(sourceMgr, targetMgr, sourceRowCount, sourceColumnCount, fromRow, fromColumn, toRow, toColumn, fromRowCount, fromColumnCount, toRowCount, toColumnCount, cellFormulas, rangeFormulas, offsetSelf, out dictionary3);
            ReferenceValidateVisitor visitor = new ReferenceValidateVisitor(new int?(sourceRowCount - 1), new int?(sourceColumnCount - 1));

            Clear(targetMgr, FormulaOperatorHelper.Indexs2Identity(toRow, toColumn, (toRow + toRowCount) - 1, (toColumn + toColumnCount) - 1));
            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair2 in dictionary3)
            {
                if (pair2.Value == null)
                {
                    targetMgr.ClearExpression(pair2.Key);
                }
                else
                {
                    int            num;
                    int            num2;
                    int            num3;
                    int            num4;
                    CalcExpression expr = pair2.Value;
                    FormulaOperatorHelper.Identity2Indexs(pair2.Key, out num, out num2, out num3, out num4);
                    num  = (num < 0) ? 0 : num;
                    num2 = (num2 < 0) ? 0 : num2;
                    num3 = (num3 < 0) ? 0 : num3;
                    num4 = (num4 < 0) ? 0 : num4;
                    expr = visitor.Visit(expr, num, num2);
                    if (expr is CalcSharedExpression)
                    {
                        expr = visitor.Visit(expr, num3, num4);
                    }
                    bool?isArrayFormula = null;
                    CalcExpressionHelper.SetExpression(targetMgr, pair2.Key, expr, isArrayFormula);
                }
                targetMgr.Invalidate(pair2.Key, false);
            }
        }
예제 #27
0
        /// <summary>
        /// Sets the formula.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="formula">The formula.</param>
        /// <param name="isArrayFormula">Indicates the formula is array formula or not.</param>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception>
        public void SetFormula(CalcRangeIdentity id, string formula, bool isArrayFormula = true)
        {
            if (object.ReferenceEquals(id, null))
            {
                throw new ArgumentNullException("id");
            }
            CalcExpression expr = this.Parser.Parse(formula, this.Source.GetParserContext(id));

            this.SetExpression(id, expr, isArrayFormula);
        }
예제 #28
0
        public static SheetCellRange[] ExtractAllExternalReference(ICalcEvaluator evaluator, string formula)
        {
            CalcExpression expression = FormulaUtility.Formula2Expression(evaluator, formula);

            if (expression == null)
            {
                return(null);
            }
            return(ExtractAllExternalReference(evaluator, expression));
        }
예제 #29
0
파일: Sparkline.cs 프로젝트: Daoting/dt
 internal void Init()
 {
     this.data            = null;
     this.group           = null;
     this.dataReference   = null;
     this.dataOrientation = Dt.Cells.Data.DataOrientation.Vertical;
     this.Row             = 0;
     this.Column          = 0;
     this.cachedFormula   = null;
 }
예제 #30
0
 public void RemoveRows(int row, int count)
 {
     foreach (SparklineGroup group in this.Groups.ToArray())
     {
         if (group.DisplayDateAxis)
         {
             CalcExpression expression = RemoveRowRange(row, count, group.DateAxisReference);
             if (expression != null)
             {
                 if (group.DateAxisReference != expression)
                 {
                     group.DateAxisReference = expression;
                 }
             }
             else
             {
                 group.Clear();
                 this.Remove(group);
                 continue;
             }
         }
         Sparkline[] array = new Sparkline[group.Count];
         group.CopyTo(array, 0);
         foreach (Sparkline sparkline in array)
         {
             if ((sparkline.Row >= row) && (sparkline.Row < (row + count)))
             {
                 group.Remove(sparkline);
             }
             else
             {
                 if (row <= sparkline.Row)
                 {
                     sparkline.Row -= count;
                 }
                 CalcExpression expression2 = RemoveRowRange(row, count, sparkline.DataReference);
                 if (expression2 != null)
                 {
                     if (sparkline.DataReference != expression2)
                     {
                         sparkline.DataReference = expression2;
                     }
                 }
                 else
                 {
                     group.Remove(sparkline);
                 }
             }
         }
         if (group.Count <= 0)
         {
             this.Remove(group);
         }
     }
 }