/** 168. Excel Sheet Column Title * 12.12 by Mingyang * Be sure to note the case of Z for 0!!! */ Public StaticString Converttotitle (intN) {if(n <= 0) return" "; StringBuffer SB=NewStringBuffer (); while(N > 0) { intTEMP = n 26; N= N/26; if(temp = = 0) {Sb.insert (0, ' Z '); N--; Continue; } Sb.insert (0, Character.tochars (64 +temp)); } returnsb.tostring (); } //The online short wording, here avoids the discussion of 26, because after 26-1=25, you can directly add Public StaticString ConvertToTitle1 (intN) {StringBuilder sb=NewStringBuilder (); while(N > 0) {n--; CharCH = (Char) (n% + ' A '); N/= 26; Sb.insert (0, CH); } returnsb.tostring (); } /** So about the problem of the system, we convert from 26 to 10 in the system and how to solve it? Please look at this question to try to counter the problem.*/ Public intTitletonumber (String s) {intresult = 0; for(inti = 0; I < s.length (); i++) {result= result * + 1 + s.charat (i)-' A '; } returnresult; }
168. Excel Sheet Column Title