Example #1
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");
            }
        }