get Index Of Excel Column - Java Native OS

Java examples for Native OS:Excel

Description

get Index Of Excel Column

Demo Code


//package com.java2s;

public class Main {
    public static int getIndexOfColumn(String col) {
        return letter2Int(col);
    }//from   ww  w  .  ja va 2s  .c om

    private static int letter2Int(String col) {
        String columnName = col.toUpperCase();
        int value = 0;
        for (int i = 0; i < columnName.length(); i++) {
            int delta = (columnName.charAt(i)) - 64;
            value = value * 26 + delta;
        }

        return value - 1;
    }
}

Related Tutorials