stackoverflow有一个c#写法
private string GetExcelColumnName(int columnNumber)
{
int dividend = columnNumber;
string columnName = String.Empty;
int modulo;
while (dividend > 0)
{
modulo = (dividend - 1) % 26;
columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
dividend = (int)((dividend - modulo) / 26);
}
return columnName;
}
{
int dividend = columnNumber;
string columnName = String.Empty;
int modulo;
while (dividend > 0)
{
modulo = (dividend - 1) % 26;
columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
dividend = (int)((dividend - modulo) / 26);
}
return columnName;
}
公司需求,我就改写成python了
def GetExcelColumnName(columnNumber):
dividend = columnNumber
columnName = ""
while(dividend>0):
modulo = (dividend - 1) % 26
columnName = chr(65+modulo) + columnName
dividend = int((dividend - modulo)/26)
return columnName
dividend = columnNumber
columnName = ""
while(dividend>0):
modulo = (dividend - 1) % 26
columnName = chr(65+modulo) + columnName
dividend = int((dividend - modulo)/26)
return columnName