I'm writing a script to import a large excel spreadhseet into an SQL Server 2008 database. Everything is working fine except for one minor detail:
If a cell in the sheet has multiple options (like a <select>
dropdown menu), only the selected option gets grabbed. I want to grab every possible option the cell has, not just the one being used (See my SQL query for why)
I have searched google and S/O for answers but I have not encountered a solution for this particular situation. Here is a link to the Spreadsheet Functions I am using.
I cannot show you the excel sheet, but it is safe to assume the traversing of the sheet is correct (I have tested it).
Here is my code:
<cfspreadsheet action="read" src="spreadsheet.xlsx" name="sheet">
<cfoutput>
#sheet.rowcount-3#
<cfloop from="2" to="#sheet.rowcount-3#" index="row">
<cfquery datasource="Questions" result="rState">
INSERT INTO States
(
State,
StateAbbr
)
VALUES
(
<cfqueryparam cfsqltype="cf_sql_varchar" value="#SpreadsheetGetCellValue(sheet,row,1)#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#SpreadsheetGetCellValue(sheet,row,2)#">
)
</cfquery>
#SpreadsheetGetCellValue(sheet,row,1)#<br />
#SpreadsheetGetCellValue(sheet,row,2)#<br />
<cfloop from="3" to="15" index="col"> <!--- multi row selection (edit based on excel sheet col relationship) --->
<cfif SpreadsheetGetCellValue(sheet,row,col) EQ "">
<cfset SpreadsheetSetCellValue(sheet,"N/A",row,col) />
</cfif>
<cfquery datasource="Questions" result="rResponse">
IF NOT EXISTS
(
SELECT Response
FROM Responses
WHERE Response=<cfqueryparam cfsqltype="cf_sql_nvarchar" value="#SpreadsheetGetCellValue(sheet,row,col)#">
)
INSERT INTO Responses
(
Response
)
VALUES
(
<cfqueryparam cfsqltype="cf_sql_nvarchar" value="#SpreadsheetGetCellValue(sheet,row,col)#">
)
</cfquery>
#row#X#col#<br />
#SpreadsheetGetCellValue(sheet,row,col)#<br />
</cfloop>
</cfloop>
</cfoutput>
Edit: I cannot show the excel sheet I'm using, but I recreated the list so you know what sort of drop down cell I am talking about. NOTE: The sheet I'm using, the options list was NOT built with cells, the creator used static values in the validation clause!!!
SpreadsheetGetCellValue()
instead? – Miguel-F Sep 17 '13 at 18:58IF NOT EXISTS...
part. So I am still not clear about the answer to my earlier question: Why do you need options that were not selected? Or is the problem that the spreadsheet functions are not returning all of the selected options? – Leigh Sep 17 '13 at 19:03