Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access query column with multiple words?

I'm using a cfspreadsheet read to read a sheet into a query object.

<cfspreadsheet action="read" src="TestExcel.xls" sheet="1" query="spreadsheetData" headerrow="1" excludeHeaderRow="true"> 

The problem is, some of the headers contain more than one word. So I end up with a query a bit like this:

ID  Name    Start Date  End Date
3   Test    1/1/2009    1/1/2013
17  Test 2  11/11/2010  11/11/2012

If I try to access one of the columns that have a space in the column name, I get an error.

<cfoutput query="spreadsheetData">
   #start date#
</cfoutput>

I've tried #[start date]# as well, but that didn't work. I cannot control the format of the excel sheet that I receive. Is there any way to access the multiple-worded-header columns?

like image 328
froadie Avatar asked May 20 '12 12:05

froadie


People also ask

How do you add a multivalued field in Access?

Create a multivalued fieldClick in the Data Type column for that row, click the arrow and then, in the drop-down list, select Lookup Wizard. Note The Lookup Wizard creates three types of lists depending on the choices you make in the wizard: a lookup field, a values list field, and a multivalued field.

How do I filter multiple values in an Access query?

Right-click the field you want to filter. To filter on multiple columns or controls, you must either select and filter each column or control separately, or use an advanced filter option.


1 Answers

When using bracket notation the contents must end up as a string, so:

<cfoutput query="spreadsheetData">
    #spreadsheetData['start date'][CurrentRow]#
</cfoutput>


If you don't use quotes, you are passing in a variable, which is done like so:

<cfset ColumnName = 'start date' />

<cfoutput query="spreadsheetData">
    #spreadsheetData[ColumnName][CurrentRow]#
</cfoutput>


Note that you must use the query name before the brackets - if you simply write [ColumnName] then this is inline array creation notation, not accessing the variable.

Also, if using this outside of a query loop (i.e. not within cfoutput/cfloop with query attribute), you also need to scope the CurrentRow variable, i.e.

spreadsheetData[ColumnName][spreadsheetData.CurrentRow]

(or provide your own explicit number/variable).


As Leigh notes below, for cfspreadsheet-specific behaviour, you can also specify the columnnames attribute, to rename the column to something directly accessible, e.g.

<cfspreadsheet query=".." columnNames="Foo,Bar,StartDate,Etcetera" ..>
like image 56
Peter Boughton Avatar answered Nov 03 '22 02:11

Peter Boughton