Skip to content

Instantly share code, notes, and snippets.

@martincapello
Created July 27, 2021 17:27
Show Gist options
  • Save martincapello/074146e5317e1ff85080f2967dc58f4b to your computer and use it in GitHub Desktop.
Save martincapello/074146e5317e1ff85080f2967dc58f4b to your computer and use it in GitHub Desktop.
Recursive function to convert an integer to a column name in A1 notation. I used this to convert array indexes to column names in Google's Spreadsheets.
func indexToA1Notation(column int) string {
if column <= 'Z'-'A' {
return string(rune('A' + column))
}
return fmt.Sprintf("%s%s", indexToA1Notation((column/26)-1), string(rune('A'+column%26)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment