close

ex: 輸入1,27,53,結果為A,A1,B1

public static string ConvertToExcelColumn(int iValue)
{    
    string strReturn = "";
    
    int iQuotient = iValue / 26;//商數
    int iRemainder = iValue % 26;//餘數
    
    if (iRemainder == 0)
    iQuotient--;  // 剛好整除的時候,商數要減一
    
    if (iQuotient > 0)
    strReturn = Convert.ToChar(64 + iQuotient).ToString();//A 65 利用ASCII做轉換
    
    if (iRemainder == 0)
    strReturn += "Z";
    else
    strReturn += Convert.ToChar(64 + iRemainder).ToString();    //A 65 利用ASCII做轉換
    
    return strReturn;
}

arrow
arrow
    全站熱搜

    felixhuang 發表在 痞客邦 留言(0) 人氣()