How to convert a column number (e.g. 127) into an Excel column (e.g. AA)

前端 未结 30 2149
鱼传尺愫
鱼传尺愫 2020-11-22 00:35

How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel.

Excel 2007 has a possible range o

30条回答
  •  故里飘歌
    2020-11-22 00:50

    Here's my super late implementation in PHP. This one's recursive. I wrote it just before I found this post. I wanted to see if others had solved this problem already...

    public function GetColumn($intNumber, $strCol = null) {
    
        if ($intNumber > 0) {
            $intRem = ($intNumber - 1) % 26;
            $strCol = $this->GetColumn(intval(($intNumber - $intRem) / 26), sprintf('%s%s', chr(65 + $intRem), $strCol));
        }
    
        return $strCol;
    }
    

提交回复
热议问题