예제 #1
0
        /// <summary>
        /// 根据行号列号返回  A1 表示的字符串
        /// 注意:不支持ZZ以后的列
        /// </summary>
        /// <param name="rowIndex"></param>
        /// <param name="columnIndex"></param>
        /// <returns></returns>
        public static string GetReferenceByIndex(int rowIndex, int columnIndex)
        {
            string result = "";
            int    div, mod;

            div = Math.DivRem(columnIndex - 1, 26, out mod);

            if (div > 0)
            {
                result = I3MathUtil.Chr(div + 64);
            }

            result = result + I3MathUtil.Chr(mod + 64 + 1);
            result = result + rowIndex.ToString();

            return(result);
        }
예제 #2
0
        /// <summary>
        /// 从 A1 形式字符串得到行号列号
        /// 注意:不支持ZZ以后的列
        /// </summary>
        /// <param name="aReference"></param>
        /// <param name="rowIndex"></param>
        /// <param name="columnIndex"></param>
        public static void GetIndexByReference(string aReference, out int rowIndex, out int columnIndex)
        {
            string columnName = I3ReferenceUtil.GetColumnName(aReference);

            rowIndex = (int)I3ReferenceUtil.GetRowIndex(aReference);

            int div, mod;

            if (columnName.Length == 1)
            {
                div = 0;
            }
            else
            {
                div = I3MathUtil.Asc(I3StringUtil.SubString(columnName, 0, 1)) - 64;
            }


            mod = I3MathUtil.Asc(I3StringUtil.SubString(columnName, columnName.Length - 1, 1)) - 64;

            columnIndex = div * 26 + mod;
        }