Showing posts with label Number to excel column. Show all posts
Showing posts with label Number to excel column. Show all posts

Friday, March 5, 2010

Convert Numbers To Excel Columns

Another code snippet that contains a utility method to get the column character from a column number, e.g. 0 -> A or 26 -> AA


public String convertColumnNumberToChars( int i ){
int iBase = 26;
String interConversion = Integer.toString(i, iBase).toUpperCase();

char[] ac = interConversion.toCharArray();
for( int j = 0; j < ac.length; j++ ) {
int arrLen = ac.length - j - 1;
char c = ac[j];
ac[j] = (char) ('A' - arrLen + Character.digit( c, iBase ));
}
return String.copyValueOf( ac );
}

Usage:
String colChar = convertColumnNumberToChars(int columnCount)


In the next post i will also put down a method to convert a column character to column number.