提供一段Excel获取Title的标题,类似于A、AA、AAA,我们操作Excel的时候通常根据次标题来获取一定的操作范围。

/********************************************
FormatExcelColumTitle
    Purpose
        Get excel title like "A","AA","AAB".. by the column index.
        we can use the string to specified single cell with the
        row number.
    Params
        strTitle - [out]which used to receive the title name.
        lColumn - [in]the specified column index.
    Return
        None
*********************************************/
void FormatExcelColumTitle(CString& strTitle, long lColumn )
{
    static bool bFirstFlag = true;

    if (bFirstFlag )
    {
        if (lColumn > 26 )
        {
            lColumn -= 26;
        }
    }
    bFirstFlag = false;
    long lColCountLeft = lColumn/26;
    if ( lColCountLeft > 0  )
    {
        FormatExcelColumTitle(strTitle, lColCountLeft);
        CString strTemp;
        strTemp.Format(_T("%c"),64+lColumn%27);
        strTitle += strTemp;
    }
    else
    {
        CString strTemp;
        strTemp.Format(_T("%c"),64+lColumn);
        strTitle += strTemp;
        bFirstFlag = true;
    }
}

 

posted @ 2015-11-09 16:50  Arronjeck  阅读(347)  评论(0编辑  收藏  举报