Google Sheets: Convert Column Alphabet to Index Number (Kotlin)

April 7, 2019
Index to Column Alphabet. A=0, B=1, C=2
object SheetHelper {
    fun toColChar0(index: Int): Char {
        return (index + 65).toChar()
    }

    fun toColChar(index: Int): Char {
        return toColChar0(index-1)
    }

    fun toColIndex0(char: Char): Int {
        return char.toInt() - 65
    }

    fun toColIndex(char: Char): Int {
        return toColIndex0(char) + 1
    }
}
val colA = SheetHelper.toColChar0(0)
val colB = SheetHelper.toColChar0(1)
val col0 = SheetHelper.toColIndex0('A')
val col1 = SheetHelper.toColIndex0('B')
val colA = SheetHelper.toColChar(1)
val colB = SheetHelper.toColChar(2)
val col1 = SheetHelper.toColIndex('A')
val col2 = SheetHelper.toColIndex('B')
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.