Exemplo n.º 1
0
        private Ptg ParseIdentifier(String name)
        {
            if (look == ':' || look == '.')
            { // this Is a AreaReference
                GetChar();

                while (look == '.')
                { // formulas can have . or .. or ... instead of :
                    GetChar();
                }

                String first  = name;
                String second = Name;
                return(new AreaPtg(first + ":" + second));
            }

            if (look == '!')
            {
                Match('!');
                String sheetName = name;
                String first     = Name;
                short  externIdx = book.GetExternalSheetIndex(book.GetSheetIndex(sheetName));
                if (look == ':')
                {
                    Match(':');
                    String second = Name;
                    if (look == '!')
                    {
                        //The sheet name was included in both of the areas. Only really
                        //need it once
                        Match('!');
                        String third = Name;

                        if (!sheetName.Equals(second))
                        {
                            throw new Exception("Unhandled double sheet reference.");
                        }

                        return(new Area3DPtg(first + ":" + third, externIdx));
                    }
                    return(new Area3DPtg(first + ":" + second, externIdx));
                }
                return(new Ref3DPtg(first, externIdx));
            }
            if (name.Equals("TRUE", StringComparison.InvariantCultureIgnoreCase) ||
                name.Equals("FALSE", StringComparison.InvariantCultureIgnoreCase))
            {
                return(new BoolPtg(name.ToUpper()));
            }

            // This can be either a cell ref or a named range
            // Try To spot which it Is
            Regex regex   = new Regex(CELL_REFERENCE_PATTERN);
            bool  cellRef = regex.IsMatch(name);

            if (cellRef)
            {
                return(new RefPtg(name));
            }

            for (int i = 0; i < book.NumberOfNames; i++)
            {
                // named range name matching Is case insensitive
                if (book.GetNameAt(i).NameName.ToLower().Equals(name.ToLower()))
                {
                    return(new NamePtg(name, book));
                }
            }
            throw new FormulaParseException("Found reference To named range \""
                                            + name + "\", but that named range wasn't defined!");
        }