convert Excel 'AB'-like column name to digit number

/**
* A-Z 1-26
* AA-AZ 27-52
* @param column
* @return
*/
public static int getColumn(String column) {
char[] columnArray = column.toUpperCase().toCharArray();
final int grade = 26;
final char base = 'A' - 1;
int result = 0;
final int maxIndex = columnArray.length - 1;
for (int i = maxIndex ; i >= 0; i--) {
result += (columnArray[i] - base) * Math.pow(grade, maxIndex - i);
}
return result;
}
 

 this is what so called 26-coded decimal, haha

你可能感兴趣的:(Excel)