开发者

ColdFusion Query -- Get index of column by column name

开发者 https://www.devze.com 2023-02-18 16:19 出处:网络
I have a column name and, for the sake of SpreadsheetSetCellFormula, I want to get the index of that column from its name.This is important for expandability, as columns may be added or taken away in

I have a column name and, for the sake of SpreadsheetSetCellFormula, I want to get the index of that column from its name. This is important for expandability, as columns may be added or taken away in the future.

When I use queryName.ColumnList, ColdFusion automatically alphabetizes the list. However, passing it into SpreadsheetAddRows dumps the columns in original order. How can I get the index of a column from its n开发者_JAVA百科ame?


<!--- get the column list, in the original order, as a coldfusion compatible array --->
<cfset variables.columnArray = createObject("java","java.util.Vector").init(
   createObject("java","java.util.Arrays").asList(
      query.getColumnList()
   )
)/>
<!--- get the index of the column. note that this is case sensitive. --->
<cfset variables.myColumnIndex = variables.columnArray.indexOf("MY_COLUMN")/>

No looping required.


This doesn't directly answer your question, however this may be VERY useful in your situation (I have used it in a similar situation)

This is taken from: http://existdissolve.com/2010/11/quick-coldfusion-goodness/

columns = arrayToList(myquery.getMeta().getcolumnlabels())

gives you a list of the columns in their original order, with their original case sensitivity (not all upper case)


You can use the getMetaData() function, which you can read about here. This function will return an array of Columns in the correct order, including some other information. You would use it as follows:

getMetaData(queryName)
0

精彩评论

暂无评论...
验证码 换一张
取 消