Pure Programmer
Blue Matrix


Cluster Map

Project: Spreadsheet Columns

Spreadsheets often have two ways to identify a column. The first is numerically with the first column being 1, second column 2, etc. The second way is with alphabetic labels 'A' - 'Z'. To support more than 26 column labels, the next column after 'Z' is designated 'AA', then 'AB', 'AC', etc. When we reach 'ZZ' we switch to three letters 'AAA', 'AAB', 'AAC, etc.

Write a function that accepts an integer column number and returns the alphabetic label as a string. You may need to write some helper functions as well.  (HINT: a function that can convert a number to base 26 can be very helpful. See BaseConversion). Write a program to exercise the function by printing out all column labels from 'A' to 'ZZZ'. How many labels need to be printed? What label is used for the maximum column number of 32,767?

Output
$ python SpreadsheetColumns.py 1:A 2:B 3:C 4:D 5:E 6:F 7:G 8:H 9:I 10:J ... 18270:ZZR 18271:ZZS 18272:ZZT 18273:ZZU 18274:ZZV 18275:ZZW 18276:ZZX 18277:ZZY 18278:ZZZ 32767:AVLG

Solution