Search code examples
coldfusioncfspreadsheet

Query created from Query returned from cfspreadsheet not having proper values


Today I came across a very odd case while reading a vlue from a spreadsheet and trying to filter them on a condition and a create a spreadsheet from the filtered data. Here are my steps

  1. Read Excel sheet

    <cfspreadsheet action="read" src="#local.sFilePath#"    excludeHeaderRow="true" headerrow ="1" query="local.qExcelData" sheet="1" />
    
  2. Create a holding Query

    <cfset local.columnNames = "LoanNumber,Product," />
    <cfset local.qSuccessData = queryNew(local.columnNames,"VarChar,VarChar") />
    
  3. Filter the Excel returned query on a condition and add the valid ones into the new Holding query

    <cfloop query="local.qExcelData" >
            <cfif ListFind(local.nExceptionRowList,local.qExcelData.currentrow) EQ 0>
              <cfset queryAddRow(local.qSuccessData) />
              <cfset querySetCell(local.qSuccessData, 'LoanNumber', local.qExcelData['Loan Number']) />
              <cfset querySetCell(local.qSuccessData, 'Product', local.qExcelData['Product']) />
            </cfif>
    </cfloop>
    
  4. Create the new spreadsheet

    <cfspreadsheet action="write" query="local.qSuccessData" filename="#local.sTempSuccessFile#" overwrite="true">
    

However I am getting the following content in my excel sheet

Loannumber                           Product
coldfusion.sql.column@87875656we    coldfusion.sql.column@89989ER

Please help on this to get it work.


Solution

  • I believe the query loop is not mapping values to the Holding-Query properly.

    Please modify your loop as below:

    <cfloop query="local.qExcelData" >
        <cfif ListFind(local.nExceptionRowList,local.qExcelData.currentrow) EQ 0>
          <cfset queryAddRow(local.qSuccessData) />
          <cfset querySetCell(local.qSuccessData, 'LoanNumber', local.qExcelData['Loan Number'][currentRow]) />
          <cfset querySetCell(local.qSuccessData, 'Product', local.qExcelData['Product'][currentRow]) />
        </cfif>
    </cfloop>