Static voidMain (string[] args) {Console.WriteLine ("1:"+ Colnumnertocolcode (1)); Console.WriteLine ("2:"+ Colnumnertocolcode (2)); Console.WriteLine ("3:"+ Colnumnertocolcode (3)); Console.WriteLine ("4:"+ Colnumnertocolcode (4)); Console.WriteLine (":"+ Colnumnertocolcode ( -)); Console.WriteLine ("£ º"+ Colnumnertocolcode ( $)); Console.WriteLine ("703:"+ Colnumnertocolcode (703)); Console.read (); } /// <summary> ///Convert a column number to a column letter in Excel/// </summary> /// <param name= "index" ></param> /// <returns></returns> Static stringColnumnertocolcode (intindex) { if(Index <=0) Throw NewException ("invaild parameter"); Index--; List<string> chars =Newlist<string>(); Do { if(chars. Count >0) Index--; Chars. Insert (0, ((Char) (Index% -+ (int)'A')). ToString ()); Index= (int) ((Index-index% -) / -); } while(Index >0); returnString.Join (string. Empty, chars. ToArray ()); }
Output:
1, 2, 3, 4 converted to A, B, C, D