예제 #1
0
        internal static AddressType IsValid(string Address)
        {
            string ws = "";

            if (Address.StartsWith("'"))
            {
                int ix = Address.IndexOf('\'', 1);
                if (ix > -1)
                {
                    ws      = Address.Substring(1, ix - 1);
                    Address = Address.Substring(ix + 2);
                }
            }
            if (Address.IndexOfAny(new char[] { '(', ')', '+', '-', '*', '/', '.', '=', '^', '&', '%', '\"' }) > -1)
            {
                return(AddressType.Invalid);
            }
            if (Address.IndexOf('!') > 0)
            {
                string[] split = Address.Split('!');
                if (split.Length == 2)
                {
                    ws      = split[0];
                    Address = split[1];
                }
                else if (split.Length == 3 && split[1] == "#REF" && split[2] == "")
                {
                    ws      = split[0];
                    Address = "#REF!";
                    if (ws.StartsWith("[") && ws.IndexOf("]") > 1)
                    {
                        return(AddressType.ExternalAddress);
                    }
                    else
                    {
                        return(AddressType.InternalAddress);
                    }
                }
                else
                {
                    return(AddressType.Invalid);
                }
            }
            int _fromRow, _fromCol, _toRow, _toCol;

            if (ExcelAddressBase.GetRowColFromAddress(Address, out _fromRow, out _fromCol, out _toRow, out _toCol))
            {
                if (_fromRow > 0 && _fromCol > 0 && _toRow <= ExcelPackage.MaxRows && _toCol <= ExcelPackage.MaxColumns)
                {
                    if (ws.StartsWith("[") && ws.IndexOf("]") > 1)
                    {
                        return(AddressType.ExternalAddress);
                    }
                    else
                    {
                        return(AddressType.InternalAddress);
                    }
                }
                else
                {
                    return(AddressType.Invalid);
                }
            }
            else
            {
                if (IsValidName(Address))
                {
                    if (ws.StartsWith("[") && ws.IndexOf("]") > 1)
                    {
                        return(AddressType.ExternalName);
                    }
                    else
                    {
                        return(AddressType.InternalName);
                    }
                }
                else
                {
                    return(AddressType.Invalid);
                }
            }
        }