1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public class ExcelSheetColumnTitle { public String convertToTitle(int n) { assert n > 0; String result = ""; while (n > 0) { int mod = n % 26; result = cal(mod) + result; n = n / 26; if (mod == 0) { n--; } } return result; } private char cal(int i) { i = (i + 26 - 1) % 26; return (char) ('A' + i); } }
|