Skip to content

Instantly share code, notes, and snippets.

@Willshaw
Last active November 21, 2017 15:04
Show Gist options
  • Save Willshaw/92e26810f95c867905721bdd6c90b84b to your computer and use it in GitHub Desktop.
Save Willshaw/92e26810f95c867905721bdd6c90b84b to your computer and use it in GitHub Desktop.
coldfusion query to excel
<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