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

前端 未结 30 2100
鱼传尺愫
鱼传尺愫 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 is an Actionscript version:

    private var columnNumbers:Array = ['A', 'B', 'C', 'D', 'E', 'F' , 'G', 'H', 'I', 'J', 'K' ,'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    
        private function getExcelColumnName(columnNumber:int) : String{
            var dividend:int = columnNumber;
            var columnName:String = "";
            var modulo:int;
    
            while (dividend > 0)
            {
                modulo = (dividend - 1) % 26;
                columnName = columnNumbers[modulo] + columnName;
                dividend = int((dividend - modulo) / 26);
            } 
    
            return columnName;
        }
    

提交回复
热议问题