Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "errors"
- "fmt"
- )
- func main() {
- for cm := 1; cm < 100; cm++ {
- cmName, _ := ColumnNumberToName(cm)
- fmt.Println(cmName)
- }
- }
- func ColumnNumberToName(num int) (string, error) {
- if num < 1 {
- return "", fmt.Errorf("incorrect column number %d", num)
- }
- if num > 16384 {
- return "", errors.New("column number exceeds maximum limit")
- }
- var col string
- for num > 0 {
- col = string(rune((num-1)%26+65)) + col
- num = (num - 1) / 26
- }
- return col, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement