Created
October 29, 2012 21:36
-
-
Save carloszaragoza/3976696 to your computer and use it in GitHub Desktop.
Export data to CSV from ColdFusion
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
<!--- Read data from two datasource tables. ---> | |
<cfquery | |
name="iae1" datasource="escolar_db13"> | |
select * from v_rc_iae_pr1 | |
</cfquery> | |
<cfscript> | |
//Use an absolute path for the files. ---> | |
theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); | |
theFile=theDir & "exportData.xls"; | |
//Create two empty ColdFusion spreadsheet objects. ---> | |
theSheet = SpreadsheetNew("DATOS REGIONAL"); | |
//Populate each object with a query. ---> | |
SpreadsheetAddRows(theSheet,iae1); | |
</cfscript> | |
<cfspreadsheet action="write" filename="#theFile#" name="theSheet" | |
sheetname="iae1" overwrite=true> | |
<cfspreadsheet action="read" src="#theFile#" sheet=1 format="csv" name="csvData"> | |
<cfspreadsheet action="write" filename="#theFile#" name="CSVData" | |
format="csv" sheetname="iae1" overwrite=true> | |
<a href="exportData.xls">Descargar</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment