Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <CFPARAM NAME="URL.DataFormat" DEFAULT="m/d/yy h:mm">
- <CFOUTPUT>
- <h1>CF9/10 CFSpreadsheet Dataformat Test</h1>
- <b>Preferred date format:</b> "m/d/yy h:mm"<br>
- <b>Problem:</b> Query date/times not properly formatted when converting to Excel.<br>
- <form action="#CGI.Script_name#" method="get">
- <b>Data Format:</b> <input type="text" name="DataFormat" value="#URL.DataFormat#" size=25>
- <input type="submit" name="Go" value="Generate Excel File">
- </form>
- <fieldset><legend>"built-in" Date formats</legend><pre>m/d/yy
- d-mmm-yy
- d-mmm
- mmm-yy
- h:mm AM/PM
- h:mm:ss AM/PM
- h:mm
- h:mm:ss
- m/d/yy h:mm
- mm:ss
- [h]:mm:ss
- mm:ss.0</pre></fieldset>
- </CFOUTPUT>
- <CFIF NOT StructKeyExists(URL, "Go")>
- <CFEXIT>
- </CFIF>
- <cfset q = queryNew("Name,Date", "varchar,date")>
- <cfloop index="x" from="1" to="10">
- <cfset queryAddRow(q)>
- <cfset querySetCell(q, "Name", "Name #x#")>
- <cfset querySetCell(q, "Date", now())>
- </cfloop>
- <cfset dfStyle = {dataformat = trim(URL.DataFormat)}>
- <cfset o = spreadsheetNew('dateTest', true)>
- <cfset spreadsheetAddRows(o, q)>
- <cfset spreadsheetFormatColumn(o, dfStyle, 2)>
- <cfset bin = spreadsheetReadBinary(o)>
- <cfheader name="Content-Disposition" value="attachment; filename=dateTest_#dateFormat(now(), 'ddmmmyyyy')#.xls">
- <!--- or try using "application/vnd-ms.excel" as cfcontent type --->
- <cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#bin#" reset="true">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement