예제 #1
0
 /// <summary>
 /// Sets up/sends information to load the Spreadsheet GUI
 /// </summary>
 private void HandleLoadSpreadsheet()
 {
     for (int r = 0; r < 99; r++)
     {
         for (int c = 0; c < 26; c++)
         {
             window.SetCellValue(r, c, sheet.GetCellValue(getCellName(r, c)).ToString());
         }
     }
     window.NameBox = selectedCell;
     window.SetCellSelection(getColumn(selectedCell), getRow(selectedCell));
 }
예제 #2
0
        /// <summary>
        /// Update the text inside the cell in the spreadsheet to
        /// reflect the evaluated value.
        /// </summary>
        /// <param name="cellName">The name of the cell being refreshed.</param>
        private void UpdateCell(string cellName)
        {
            int    colIndex;
            int    rowIndex;
            string cellValue;

            // Helper methods to decode the index of the cell's row and column
            colIndex = GetColumnIndex(cellName);
            rowIndex = GetRowIndex(cellName);

            // Refresh the value of the cell (a FormulaError or a value)
            if ((spreadsheet.GetCellValue(cellName) is FormulaError))
            {
                FormulaError error = (FormulaError)spreadsheet.GetCellValue(cellName);
                cellValue = error.Reason;
            }
            else
            {
                cellValue = spreadsheet.GetCellValue(cellName).ToString();
            }
            window.SetCellValue(rowIndex, colIndex, cellValue);
        }
예제 #3
0
        /// <summary>
        /// Handles request to add content to selected cell
        /// </summary>
        /// <param name="content"></param>
        private void HandleSetContent(int column, int row, string content)
        {
            Spreadsheet oldSpreadsheet = new Spreadsheet();

            foreach (string name in spreadsheet.GetNamesOfAllNonemptyCells())
            {
                oldSpreadsheet.SetContentsOfCell(name, spreadsheet.GetCellContents(name).ToString());
            }
            try
            {
                if (content != "")
                {
                    foreach (string name in spreadsheet.SetContentsOfCell(getCellName(column, row), content))
                    {
                        int    col            = name.ToCharArray()[0] - 65;
                        int    ro             = int.Parse(name.Substring(1));
                        object contentToCheck = spreadsheet.GetCellValue(name);
                        if (contentToCheck is FormulaError)
                        {
                            spreadsheetView.DisplayMessage(String.Format("Formula error {0}", contentToCheck.ToString()));
                            spreadsheet = oldSpreadsheet;
                            break;
                        }
                        spreadsheetView.SetCellValue(col, ro - 1, spreadsheet.GetCellValue(name).ToString());
                    }
                }
            }
            catch (FormulaFormatException e)
            {
                spreadsheetView.DisplayMessage("Formula format invalid");
            }
            catch (CircularException e)
            {
                spreadsheetView.DisplayMessage("Circular exception");
            }
        }