Last active
November 21, 2017 15:04
-
-
Save Willshaw/92e26810f95c867905721bdd6c90b84b to your computer and use it in GitHub Desktop.
coldfusion query to excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
obj_query = new core.utility.queryWrapper(); | |
lst_columns = 'id,email'; | |
lst_columns_for_sql = listQualify(lst_columns, "`" ); | |
str_select = ' | |
SELECT #lst_columns_for_sql# | |
FROM `allcars`.`users` | |
WHERE `channelSource` = 389; | |
'; | |
skv_select = obj_query.execute( str_select ); | |
output = ''; | |
if( skv_select.success ) { | |
results = skv_select.data[1]; | |
// build spreadsheet object | |
spreadsheet = SpreadsheetNew('users',false); | |
// add data rows | |
SpreadSheetAddRows(spreadsheet,results); | |
// add headers | |
SpreadSheetAddRow(spreadsheet, lst_columns, 1, 1); | |
output = spreadsheetReadBinary(spreadsheet); | |
} | |
</cfscript> | |
<cfheader name="content-disposition" value="attachment; filename=users.xls"> | |
<cfcontent type="application/msexcel" variable="#output#"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment