Created
July 27, 2021 17:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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