Exemple #1
0
        /// <summary>
        /// Returns the row number from the cellAddress
        /// e.g. D5 would return 5
        /// </summary>
        /// <param name="cellAddress">An Excel format cell addresss (e.g. D5)</param>
        /// <returns>The row number</returns>
        public static int GetRowNumber(string cellAddress)
        {
            // find out position where characters stop and numbers begin
            int  iPos  = 0;
            bool found = false;

            foreach (char chr in cellAddress.ToCharArray())
            {
                iPos++;
                if (char.IsNumber(chr))
                {
                    found = true;
                    break;
                }
            }
            if (found)
            {
                string NumberPart = cellAddress.Substring(iPos - 1, cellAddress.Length - (iPos - 1));
                if (ExcelCell.IsNumericValue(NumberPart))
                {
                    return(int.Parse(NumberPart));
                }
            }
            return(0);
        }