Format columns for data intended for Excel
Hello, everyone.
I'm working on a document that runs a query, populates a <table> with the data, and then spits out an Excel sheet for the user to either open or save. I'm using the CFSCRIPT equivalent of CFCONTENT and CFHEADER to create the Excel file.
<cfscript>
pc = getpagecontext().getresponse();
pc.getresponse().setcontenttype('application/vnd-ms.excel');
pc.setHeader("Content-Disposition","attachment;filename=ThisData_#DateFormat(now(),'yyyy-mm-dd')#.xls");
</cfscript>Everything is working great, with one exception.
One of the query columns that is being returned is a datatype of varchar(10) - the data is a 'month year' value like "May 2010" or "Jun 2011". If you look at the data in a browser, it appears in that format ("month year"). But when the Excel file is created, it shows up as "May-12" or "Dec-12" (regardless of the month, the date is always 12.)
I'm pretty sure this is because in Excel the column is formatted as "General" when I need it to be "Text". Is there a way to tell CF that a particular column in Excel needs to be formatted a particular way?
Thanks,
^_^
