f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/main/java/io/protobase/f7/utils/AlphaUtils.java
-rw-r--r--
665
 1package io.protobase.f7.utils;
 2
 3public class AlphaUtils {
 4  /**
 5   * Convert a column in A1 notation (where column is A, B, C... ZA, ZB... etc.) to integer (A=1, B=2)
 6   *
 7   * @param column to convert to zero-indexed int.
 8   * @return int greater than or equal to 1.
 9   */
10  public static int columnToInt(String column) {
11    int result = -1;
12    for (char character : column.toLowerCase().toCharArray()) {
13      int pos = character - 'a';
14      if (result != -1) {
15        result = result + 26 + pos;
16      } else {
17        result = pos;
18      }
19    }
20    return result;
21  }
22
23  public static int rowToInt(String row) {
24    return Integer.parseInt(row) - 1;
25  }
26}