zoukankan      html  css  js  c++  java
  • 1、2、3、4 转换成 A、B、C、D

            static void Main(string[] args)
            {
                Console.WriteLine("1  :" + ColNumnerToColCode(1));
                Console.WriteLine("2  :" + ColNumnerToColCode(2));
                Console.WriteLine("3  :" + ColNumnerToColCode(3));
                Console.WriteLine("4  :" + ColNumnerToColCode(4));
                Console.WriteLine("27 :" + ColNumnerToColCode(27));
                Console.WriteLine("36 :" + ColNumnerToColCode(36));
                Console.WriteLine("703:" + ColNumnerToColCode(703));
                Console.Read();
            }
    
            /// <summary>
            /// 将列号转换为Excel中的列字母
            /// </summary>
            /// <param name="index"></param>
            /// <returns></returns>
            static string ColNumnerToColCode(int index)
            {
                if (index <= 0)
                    throw new Exception("invaild parameter");
                index--;
                List<string> chars = new List<string>();
                do
                {
                    if (chars.Count > 0)
                        index--;
                    chars.Insert(0, ((char)(index % 26 + (int)'A')).ToString());
                    index = (int)((index - index % 26) / 26);
                } while (index > 0);
    
                return String.Join(string.Empty, chars.ToArray());
            }

    输出:

  • 相关阅读:
    pymysql模块及mysql备份
    html基本标签使用
    索引
    多表查询
    Http协议以及请求响应
    web服务器tomcat以及servlet
    XML笔记
    Javascript(2)——BOM
    静态资源三剑客——JavaScript(1)
    静态资源三剑客——CSS
  • 原文地址:https://www.cnblogs.com/uncleJOKER/p/5552423.html
Copyright © 2011-2022 走看看