def index_to_column(idx):
  """Turns an index into a letter representing a spreadsheet column."""
  letter = chr(65 + idx % 26)
  q = idx // 26
  if q == 0:
    return letter
  else:
    return index_to_column(q-1) + letter