예제 #1
0
        /// <summary>
        /// Parse cell from the part of the string
        /// </summary>
        /// <param name="reference">Textual cell reference, e.g. A1</param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static Cell Parse(String reference, int offset, int count)
        {
            int row = 0;
            int col = 0;

            for (int i = offset; i < offset + count; i++)
            {
                if (Char.IsDigit(reference[i]))
                {
                    row = 10 * row + (reference[i] - '0');
                }
                else if (Char.IsLetter(reference[i]))
                {
                    col = 26 * col + (Char.ToUpper(reference[i]) - 'A') + 1;
                }
                else
                {
                    throw ExceptionFactory.Argument("Value '{0}' is not a valid cell reference!", reference.Substring(offset, count));
                }
            }
            return(new Cell {
                Col = col - 1, Row = row - 1
            });
        }