ExcelWriter is compatible with Cold Fusion. However, you can only save the newly created excel file to hard disk on your server. Our Save method options of saOpenInPlace (to open the file with Excel directly in the client browser) and saOpenInExcel (to stream the file to the client and force a SaveAs dialog that allows them to open directly in Excel or save to their local disk) will not work in Cold Fusion. These functions require the Response object of ASP. You must save the newly created file on the server and then use a Redirect to download it to the client machine.
Below is a sample of using ExcelWriter with ColdFusion. It is also attached as a file to this article.
<HTML>
<HEAD>
<TITLE>SoftArtisans ExcelWriter - Database Display Sample - ColdFusion</TITLE>
</HEAD>
<BODY>
<Center>
<H1>SoftArtisans ExcelWriter - ColdFusion Sample </H1> </Center>
<P>
</P>
Description: This sample uses a database of customers that have made
reservations in the past.<BR>
This sample displays Database Rendered Data.
<P>
</P>
<!--- Create an Instance of ExcelWriter--->
<cfobject type="COM" name="XLS" class="Softartisans.Excelwriter" action="CREATE">
<CFSET WKSS = XLS.Worksheets>
<CFSET WKS = WKSS.Item(1)>
<CFSET FUCells = WKS.Cells>
<CFSET CellA2 = FUCells.Cell("A2")>
<!-- Apply cell formatting -->
<CFSET CellA2Format = CellA2.Format>
<CFSET HeadingFont = CellA2Format.Font>
<CFSET HeadingFont.Name = "Courier">
<CFSET HeadingFont.Bold = True>
<CFSET HeadingFont.Underline = True>
<CFSET HeadingFont.Size = "18">
<!-- Assign cell values -->
<CFSET CellA2.Value = "Summary of Customer Accounts">
<CfSet CellA3 = FUCells.Cell("A3")>
<CfSet CellA3.Value = "Reservation Date">
<CfSet CellB3 = FUCells.Cell("B3")>
<CfSet CellB3.Value = "First Name">
<CfSet CellC3 = FUCells.Cell("C3")>
<CfSet CellC3.Value = "Last Name">
<CfSet CellD3 = FUCells.Cell("D3")>
<CfSet CellD3.Value = "Amount Due">
<CfSet CellE3 = FUCells.Cell("E3")>
<CfSet CellE3.Value = "Billing Address">
<CfSet CellF3 = FUCells.Cell("F3")>
<CfSet CellF3.Value = "City">
<CfSet CellG3 = FUCells.Cell("G3")>
<CfSet CellG3.Value = "State">
<CfSet CellH3 = FUCells.Cell("H3")>
<CfSet CellH3.Value = "Postal Code">
<CfSet CellI3 = FUCells.Cell("I3")>
<CfSet CellI3.Value = "Phone Number">
<CfSet CellJ3 = FUCells.Cell("J3")>
<CfSet CellJ3.Value = "Amount Paid">
<CfSet CellK3 = FUCells.Cell("K3")>
<CfSet CellK3.Value = "Total Due">
<!-- Define the created FileName and path to open-->
<CFSET fileName = "#application.ServerFilePath#\excelwritertest.xls">
<CFSet XLS.Save(fileName,0,7) >
<CFSET Record = "">
<cfcontent type="application/msexcel"
file="#application.ServerFilePath#\excelwritertest.xls"
deletefile="Yes">
</body>
</html>
|