excel根据列序号计算出对应的列字母

来源:互联网 发布:thinkpad推荐 知乎 编辑:程序博客网 时间:2024/05/16 10:37
public static String getColumnByNum(int index){
if (index <= 0) {                 
try {                         
throw new Exception("Invalid parameter");                 
} catch (Exception e) {     
e.printStackTrace();              
}        
}        
index--;         
String column = "";         
do {                 
if (column.length() > 0) {
index--;
}
column = ((char) (index % 26 + (int) 'A')) + column;
index = (int) ((index - index % 26) / 26);
} while (index > 0);
return column;
}
0 0
原创粉丝点击