Newer
Older
csv-parser / src / main / java / com / ljunggren / csvParser / utils / ParserUtils.java
@aljunggren aljunggren on 12 May 2021 503 bytes Initial commit
package com.ljunggren.csvParser.utils;

public class ParserUtils {

    public static int columnToInt(String column) throws Exception {
        if (!column.matches("[a-zA-Z]+")) {
            throw new Exception(String.format("Column value must be a letter. Actual: %s", column));
        }
        int index = 0;
        for (int i = 0; i < column.length(); i++) {
            index *= 26;
            index += column.toUpperCase().charAt(i) - 'A' + 1;
        }
        return index - 1;
    }
    
}