在excel中也许是为了方便区分行和列,行号用数字表示,但是列却是用大写字母表示的。在对excel进行编程的时候可能需要用到数据源,我们知道数据源所在的行数和列数,行数就需要转成字母。以下代码可以将列数转为字母对应的列:
public class Main { public static void main(String[] args) { System.out.println(TranColumnLetter(1000)); } //column从0开始 private static String TranColumnLetter(int column) { String [] arr=new String[] {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S", "T","U","V","W","X","Y","Z"}; String columnStr=""; while(column>=0) { int remainder=column%26; if(remainder>=0) { columnStr=arr[remainder]+columnStr; } column=column/26-1; } return columnStr; } } 输出结果: ALM
点赞(0)
请不要重复点赞
评论列表