excel_colname

mdtools.numpy_helper_functions.excel_colname(n, upper=True)[source]

Convert an integer to its corresponding Excel-style column name.

Parameters:
  • n (int) – Column number to convert to column string. If n is negative, it will be multiplied by -1. If n is zero, the return value will be '0'.

  • upper (bool, optional) – If True (default), return upper case column name.

Returns:

col_name (str) – Excel-style column name.

Examples

>>> mdt.nph.excel_colname(0)
'0'
>>> mdt.nph.excel_colname(1)
'A'
>>> mdt.nph.excel_colname(1, upper=False)
'a'
>>> mdt.nph.excel_colname(-1)
'A'
>>> mdt.nph.excel_colname(26)
'Z'
>>> mdt.nph.excel_colname(27)
'AA'
>>> mdt.nph.excel_colname(27, upper=False)
'aa'