Пример #1
0
        public string ConvertReferences(int colmn, int row, string expr)
        {
            string CellPattern = @"[A-Z]+[0-9]+";
            Regex  regex       = new Regex(CellPattern, RegexOptions.IgnoreCase);
            Index  res;

            foreach (Match match in regex.Matches(expr))
            {
                if (dictionary.ContainsKey(match.Value))
                {
                    res = TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(match.Value);
                    if ((colmn != res.column) || (row != res.row))
                    {
                        table[colmn][row].referenceFromThisCell.Add(table[res.column][res.row]);
                        table[res.column][res.row].newReferenceToThisCell.Add(table[colmn][row]);
                    }
                    else
                    {
                        throw new Exception("There is a loop");
                    }
                }
            }
            MatchEvaluator ev      = new MatchEvaluator(referenceToValue);
            string         newExpr = regex.Replace(expr, ev);

            return(newExpr);
        }
Пример #2
0
 public Cell(int c, int r)
 {
     row             = r;
     column          = c;
     name            = Convert.ToString(TwentySixNumeralSystem.ToTwentySixBasedNumeralSystem(column)) + Convert.ToString(row);
     expr            = "";
     valueDouble     = 0.0;
     identifierValue = false;
 }
Пример #3
0
 public void Open(int colmn, int row, StreamReader str)
 {
     for (int i = 0; i < colmn; i++)
     {
         for (int j = 0; j < row; j++)
         {
             string index          = str.ReadLine();
             string expression     = str.ReadLine();
             string value          = str.ReadLine();
             string boolIdentifier = str.ReadLine();
             if (expression != "")
             {
                 dictionary[index] = value;
             }
             else
             {
                 dictionary[index] = "";
             }
             table[i][j].Expr = expression;
             if (Convert.ToBoolean(boolIdentifier) == true)
             {
                 table[i][j].IdentifierValue = true;
                 table[i][j].ValueBool       = Convert.ToBoolean(value);
             }
             else
             {
                 table[i][j].IdentifierValue = false;
                 table[i][j].ValueDouble     = Convert.ToDouble(value);
             }
             int    refCount = Convert.ToInt32(str.ReadLine());
             string refer;
             for (int k = 0; k < refCount; k++)
             {
                 refer = str.ReadLine();
                 if ((TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).row < rowsCount) && (TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).column) < columnsCount)
                 {
                     table[i][j].newReferenceToThisCell.Add(table[TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).column][TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).row]);
                 }
             }
             int refFromCount = Convert.ToInt32(str.ReadLine());
             for (int k = 0; k < refFromCount; k++)
             {
                 refer = str.ReadLine();
                 if ((TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).row < rowsCount) && (TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).column) < columnsCount)
                 {
                     table[i][j].referenceFromThisCell.Add(table[TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).column][TwentySixNumeralSystem.FromTwentySixBasedNumeralSystem(refer).row]);
                 }
             }
         }
     }
 }