49 lines
1.8 KiB
Plaintext
49 lines
1.8 KiB
Plaintext
<!---https://www.bennadel.com/blog/461-creating-microsoft-excel-documents-with-coldfusion-and-xml.htm--->
|
|
<cfparam name="ATTRIBUTES.qRead" type="query"/>
|
|
<cfparam name="ATTRIBUTES.titleMap" type="struct"/>
|
|
<cfparam name="ATTRIBUTES.sheetTitle" type="string" default="Sheet1"/>
|
|
<cfparam name="ATTRIBUTES.filename" type="string" default="export.xlsx"/>
|
|
|
|
<cfsavecontent variable="strXmlData">
|
|
<cfoutput>
|
|
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>
|
|
<meta http-equiv="content-type" content="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
|
|
<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>xlsWorksheetName</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>
|
|
<body>
|
|
<table>
|
|
<tr>
|
|
<cfloop struct=#ATTRIBUTES.titleMap# item="field">
|
|
<th>#structFind(ATTRIBUTES.titleMap,field).title#</th>
|
|
</cfloop>
|
|
</tr>
|
|
|
|
<cfloop query=#ATTRIBUTES.qRead#>
|
|
<tr>
|
|
<cfloop struct=#ATTRIBUTES.titleMap# item="field">
|
|
<td>
|
|
#ATTRIBUTES.qRead[field]#
|
|
</td>
|
|
</cfloop>
|
|
</tr>
|
|
|
|
</cfloop>
|
|
</table>
|
|
</body>
|
|
</html>
|
|
</cfoutput>
|
|
</cfsavecontent>
|
|
<cfheader
|
|
name="content-disposition"
|
|
value="attachment; filename=#ATTRIBUTES.filename#"
|
|
/>
|
|
<!---
|
|
When streaming the Excel XML data, trim the data and
|
|
replace all the inter-tag white space. No need to stream
|
|
any more content than we have to.
|
|
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
|
--->
|
|
<cfcontent
|
|
type="application/vnd.ms-excel"
|
|
variable="#ToBinary( ToBase64( strXmlData.Trim().ReplaceAll( '>\s+', '>' ).ReplaceAll( '\s+<', '<' ) ) )#"
|
|
/>
|
|
<cfexit method="exittag"/> |