def _get_column_letter(col_idx):
 if (not (1 <= col_idx <= 18278)):
  raise ValueError('Invalid column index {0}'.format(col_idx))
 letters = []
 while (col_idx > 0):
  (col_idx, remainder) = divmod(col_idx, 26)
  if (remainder == 0):
   remainder = 26
   col_idx -= 1
  letters.append(chr((remainder + 64)))
 return ''.join(reversed(letters))

def _get_column_letter ( col_idx ) : if ( not ( 1 <= col_idx <= 18278 ) ) : raise ValueError ( 'Invalid column index {0}' . format ( col_idx ) ) letters = [ ] while ( col_idx > 0 ) : ( col_idx , remainder ) = divmod ( col_idx , 26 ) if ( remainder == 0 ) : remainder = 26 col_idx -= 1 letters . append ( chr ( ( remainder + 64 ) ) ) return '' . join ( reversed ( letters ) )
convert a column number into a column letter right shift the column col_idx by 26 to find column letters in reverse order .