Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.