Search code examples
coldfusioncoldfusion-10cfspreadsheet

How to query through an excel document column using cfspreadsheet in ColdFusion?


I need to do some validation on an excel spreadsheet before I upload to database.

How do I query through an excel document column using cfspreadsheet in ColdFusion?

I need to verify that specific columns don't have any null values in any of their rows. I have the number of rows in a cold Fusion variable and the number of columns will always be the same.

Thus far, I've been able to figure out the following (below) about cfspreadsheet.

I could put the code below inside a <cfloop> and increment the column and rows with cfif statements to skip the columns I don't want to check. The loop would end with the total numberOfRows CF variable that I have, but I imagine there's a better way to do this using a query.

Can I do this in a query? If so, how?

<cfspreadsheet
  action="read" 
  format = "html"
  src="#SESSION.theFile#"
  name= "test"
  rows = "3"
  columns = "6"
  >


<cfoutput>
   #test#
</cfoutput>

Solution

  • (From comments...)

    CFSpreadsheet can return the results in several format. To work with a query object, you need to use the query attribute, not format=html. Once you have a query, you can filter it using a QoQ. CFDump the query variable first to see and understand the query columns you can access.