Exemplo n.º 1
0
        /// <summary>
        /// Try get range by specified address or range name.
        /// </summary>
        /// <param name="addressOrName">Address or range name used to find range on worksheet.</param>
        /// <param name="range">Range that was found by specified address or name on worksheet.</param>
        /// <returns>True if range was found; Otherwise return false.</returns>
        public ReferenceRange TryGetRangeByAddressOrName(string addressOrName)
        {
            ReferenceRange range = null;

            if (RangePosition.IsValidAddress(addressOrName))
            {
                range = new ReferenceRange(this, addressOrName);
            }
            else if (NamedRange.IsValidName(addressOrName))
            {
                NamedRange namedRange;

                if (this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange))
                {
                    range = new ReferenceRange(namedRange.Worksheet, namedRange.Position);
                }
            }
            return(range);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Get cell display text by specified address
 /// </summary>
 /// <param name="address">address to locate a cell</param>
 /// <returns>display text in string returned from specified cell</returns>
 public string GetCellText(string address)
 {
     if (CellPosition.IsValidAddress(address))
     {
         return(GetCellText(new CellPosition(address)));
     }
     else if (RangePosition.IsValidAddress(address))
     {
         return(GetCellText((new RangePosition(address)).StartPos));
     }
     else if (NamedRange.IsValidName(address) &&
              this.TryGetNamedRange(address, out var range))
     {
         return(GetCellText(range.StartPos));
     }
     else
     {
         throw new InvalidAddressException(address);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Try get range by specified address or range name.
        /// </summary>
        /// <param name="addressOrName">Address or range name used to find range on worksheet.</param>
        /// <param name="range">Range that was found by specified address or name on worksheet.</param>
        /// <returns>True if range was found; Otherwise return false.</returns>
        public bool TryGetRangeByAddressOrName(string addressOrName, out RangePosition range)
        {
            if (RangePosition.IsValidAddress(addressOrName))
            {
                range = new RangePosition(addressOrName);
                return(true);
            }
            else if (NamedRange.IsValidName(addressOrName))
            {
                NamedRange namedRange;

                if (this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange))
                {
                    range = (RangePosition)namedRange;
                    return(true);
                }
            }

            range = RangePosition.Empty;
            return(false);
        }