0

26 x 26 グリッドのテキスト ボックスを表示するスプレッドシート プログラムを作成しました。textbox を継承し、cellID や isFormula などの他のプロパティを含む Cell というカスタム クラスを作成しました。「=」で始まるセルは数式です。どのセルが算術関数で使用されるかがわかるように、セル内の範囲を取得するメソッドを既に作成しました。たとえば、セルの内容が =A1:A3 + B1:B3 の場合、メソッドは A1、A2、A3、B1、B2、B3 で動作していることを認識します。しかし、どのようにオペレーターを取得し、それを使用して関数を実行するのでしょうか?

       public static void GetArithmeticFunctionRange(Cell selectedCell)
       {
        List<string> cellRange = new List<string>();
        string arithmeticFunction = selectedCell.Text;
        arithmeticFunction = arithmeticFunction.Replace(" ","").Trim();
        string[] subranges = arithmeticFunction.Split('+','-','*','/');
        string tempRange = "";
        char lowerBoundLetter;
        char upperBoundLetter;
        int lowerBoundNumber = 0;
        int upperBoundNumber = 0;

           for(int i = 0; i < subranges.Length; i++){
            tempRange = subranges[i];
            if(tempRange.Contains(":")){
                string[] rangeBounds = tempRange.Split(':');
                lowerBoundLetter = rangeBounds[0][0];
                upperBoundLetter = rangeBounds[1][0]; 
                lowerBoundNumber =int.Parse(rangeBounds[0].Substring(1));
                upperBoundNumber =int.Parse(rangeBounds[1].Substring(1));
                for (char columnLetter = lowerBoundLetter; columnLetter 
                <= upperBoundLetter; columnLetter++){
                    for (int rowNumber = lowerBoundNumber; rowNumber <= 
                upperBoundNumber; rowNumber++)
                    {
                        string cell = Convert.ToString(columnLetter) + 
                Convert.ToString(rowNumber);
                        cellRange.Add(cell);
                }
             }
          }
            else
                {
                cellRange.Add(tempRange);
                }
       }    

      }
4

0 に答える 0