CFLib.org – Common Function Library Project

excelColumnNumtoColumnName(columnName)

Last updated May 3, 2010

author

Adam Tuttle

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Converts a numeric column position (i.e. 127) to its Excel Column Name (DW). Assumes column numbers are 1-based (1=A,2=B,...)

Return Values:
Returns a string.

Example:

column 1 is #ExcelColumnNumtoColumnName(1)#<br/>
column 18 is #ExcelColumnNumtoColumnName(18)#<br/>
column 100 is #ExcelColumnNumtoColumnName(100)#<br/>
column 653 is #ExcelColumnNumtoColumnName(653)#

Parameters:

Name Description Required
columnName Numeric column number. Yes

Full UDF Source:

/**
 * Converts a numeric column position to its Excel Column Name
 * 
 * @param columnName 	 Numeric column number. (Required)
 * @return Returns a string. 
 * @author Adam Tuttle (adam@fusiongrokker.com) 
 * @version 1, May 3, 2010 
 */
function excelColumnNumtoColumnName(columnNumber){
	var dividend = fix(arguments.columnNumber); //make sure input is an integer
	var columnName = '';
	var modulo = 0;
	//if dividend <= 0, an empty string will be returned
	while (dividend gt 0){
		modulo = (dividend - 1) mod 26;
		columnName = "#chr(65 + modulo)##columnName#";
		dividend = fix((dividend - modulo) / 26);
	}
	return columnName;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson