Example- storing the spreadsheet data in a CSV string

The following example reads the spreadsheet file - SingleSheet.xls and stores the spreadsheet data in a CSV string.

<cfspreadsheet action = "read"
format="csv"
src="C:\documents\SingleSheet.xls"
name="csvvar"
rows="1-4,5,6,7-8">
<cfoutput>#csvvar#</cfoutput>
<cfspreadsheet action = "read" format="csv" src="C:\documents\SingleSheet.xls" name="csvvar" rows="1-4,5,6,7-8"> <cfoutput>#csvvar#</cfoutput>
<cfspreadsheet action = "read" 
format="csv" 
src="C:\documents\SingleSheet.xls" 
name="csvvar" 
rows="1-4,5,6,7-8"> 
<cfoutput>#csvvar#</cfoutput>

The following example reads the spreadsheet file - template_02.xls and stores the spreadsheet data in a query.

<cfspreadsheet
action = "read"
src="C:\dcuments\template_02.xls"
query="excelquery"
sheet="1"
rows="1-3,4-5"
columns="1,4">
<cfoutput
query="excelquery"
startrow="1"
maxrows="#excelquery.recordcount#">
#excelquery.col_1#
#excelquery.col_2#
</cfoutput>
<cfspreadsheet action = "read" src="C:\dcuments\template_02.xls" query="excelquery" sheet="1" rows="1-3,4-5" columns="1,4"> <cfoutput query="excelquery" startrow="1" maxrows="#excelquery.recordcount#"> #excelquery.col_1# #excelquery.col_2# </cfoutput>
<cfspreadsheet 
action = "read" 
src="C:\dcuments\template_02.xls" 
query="excelquery" 
sheet="1" 
rows="1-3,4-5" 
columns="1,4"> 
<cfoutput 
query="excelquery" 
startrow="1" 
maxrows="#excelquery.recordcount#"> 
#excelquery.col_1# 
#excelquery.col_2# 
</cfoutput>

The following example reads a spreadsheet file - template_08_Charts_Graph.xls and stores the spreadsheet data in an HTML string.

<cfspreadsheet
action = "read"
format="html"
src="C:\documents\template_08_Charts_Graph.xls"
name="report1"
rows="5-11"
columns="1-6">
<cfoutput>
#report1#
</cfoutput>
<cfspreadsheet action = "read" format="html" src="C:\documents\template_08_Charts_Graph.xls" name="report1" rows="5-11" columns="1-6"> <cfoutput> #report1# </cfoutput>
<cfspreadsheet 
action = "read" 
format="html" 
src="C:\documents\template_08_Charts_Graph.xls" 
name="report1" 
rows="5-11" 
columns="1-6"> 
<cfoutput> 
#report1# 
</cfoutput>

The following example uses data from a query and writes it to a single sheet in the spreadsheet file - SingleSheet1.xls

<cfquery
name="excelquery"
datasource="cfdocexamples">
SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE='WI'
ORDER BY ParkName, State
</cfquery>
<cfspreadsheet
action = "write"
filename="C:\SingleSheet1.xls"
query="excelquery"
overwrite="true">
<cfquery name="excelquery" datasource="cfdocexamples"> SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE='WI' ORDER BY ParkName, State </cfquery> <cfspreadsheet action = "write" filename="C:\SingleSheet1.xls" query="excelquery" overwrite="true">
<cfquery 
name="excelquery" 
datasource="cfdocexamples"> 
SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE='WI' 
ORDER BY ParkName, State 
</cfquery> 
<cfspreadsheet 
action = "write" 
filename="C:\SingleSheet1.xls" 
query="excelquery" 
overwrite="true">

Get help faster and easier

New user?