Ejemplo n.º 1
0
        public void Load(string filename, bool isMainSheet)
        {
            TableData sheet           = TableFileLoader.Load(filename, sheetHashToString);
            string    sheetIdentifier = filename.Replace(".sheet", "");

            sheetHashToString[sheetIdentifier.GetHashCode()] = sheetIdentifier;
            if (isMainSheet)
            {
                mainSheet = sheetIdentifier;
            }

            sheets.Add(sheetIdentifier, sheet);
        }
Ejemplo n.º 2
0
        // return EmptyCell, ValueCell or FormulaCell based on string token
        public static ICell TokenToCell(string token)
        {
            // cell needs no further evaluation
            if (token == "[]")
            {
                return new EmptyCell();
            }
            
            
            
            if (Int32.TryParse(token, out int parsed))
            {
                ValueCell cell = new ValueCell();
                cell.Status = Error.OK;
                cell.Val = parsed;
                return cell;
            }

            if (token[0] == '=') // Is some kind of formula
            {
                string formula = token.Substring(1);
                Func<int, int ,int> op = null;
                FormulaCell cell = new FormulaCell();

                
                if (formula.Contains('+')) {
                    cell.Operation = '+';
                }
                else if (formula.Contains("-")) {
                    cell.Operation = '-';
                }
                else if (formula.Contains("*")) {
                    cell.Operation = '*';
                }
                else if (formula.Contains("/"))
                {
                    cell.Operation = '/';
                }

                if (cell.Operation == '0') // formula doesn't contain an operator
                {
                    cell.Status = Error.MISSOP;
                    cell.Evaluated = true;
                    return cell;
                }

                string[] operands = TableFileLoader.GetOperands(formula, cell.Operation);
                if (operands == null)
                {
                    // formula syntax error
                    cell.Status = Error.FORMULA;
                    cell.Evaluated = true;
                    return cell;
                }

                ILink[] links = new ILink[2];
                
                for (int i = 0; i < operands.Length; i++)
                {
                    if (operands[i].Contains('!'))
                    {
                        string[] parts = operands[i].Split('!');
                        string addr = parts[1];
                        AbsoluteLink link = new AbsoluteLink();
                        link.SheetName = parts[0];
                        Utils.GetRowColFromAddr(addr, out int row, out int col);
                        link.Row = row;
                        link.Col = col;
                        links[i] = link;
                    }
                    else
                    {
                        RelativeLink link = new RelativeLink();
                        Utils.GetRowColFromAddr(operands[i], out int row, out int col);
                        link.Row = row;
                        link.Col = col;
                        links[i] = link;
                    } 
                }

                cell.Operands = links;
                return cell;
            }
            
            // not a formula, not an empty cell
            ValueCell invalidCell = new ValueCell();
            invalidCell.Status = Error.INVVAL;
            return invalidCell;
        }