从查询创建电子表格时,生成的电子表格不允许格式化某个日期时间数据类型的列。Coldfusion生成的电子表格不允许列格式化
电子表格创作是:
<cfset filenametouse = 'AllCaseData' />
<!---Set directory and full file path--->
<cfset theDir = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<!---Attach file extension to full file path and file name--->
<cfset theFile = theDir & filenametouse & ".xls" />
<cflock name="fileActionSentItems" type="exclusive" timeout="30" throwontimeout="true">
<cfset SpreadsheetObj = spreadsheetNew()>
<!---<cfset fcol = {}>
<cfset fcol.dataformat = "@">--->
<!---Create the column headings--->
<cfset SpreadsheetAddRow(SpreadsheetObj, "Case_Number,Ship_Start,Projected_$,VA_$,Customer_ID,Customer,Project_Description,Stage,Sales,PM,J_Count,O_Count,S2_Count,S_Count,I_Count")>
<!---add the column data to the spreadsheet--->
<cfset SpreadsheetAddRows(SpreadsheetObj, caseData) />
<cfset SpreadsheetFormatColumn(SpreadsheetObj, {dataformat="m/d/yyyy"}, 2)>
<!---Generate the spreadsheet--->
<cfspreadsheet action="write" filename="#theFile#" name="SpreadsheetObj" sheetname="Sheet1" overwrite="true" />
</cflock>
<cftry>
<cflock name="fileActionSentItems" type="exclusive" timeout="30" throwontimeout="true">
<cfmail to="#session.authUser.getEmail()#" from="[email protected]" subject="All Case Data" type="html" >
<cfmailparam file="#theFile#" remove="true" />
<p>The requested data is attached.</p>
</cfmail>
</cflock>
<cfcatch type="any" >
<cffile action="delete" file="#theFile#" />
</cfcatch>
</cftry>
<cfoutput><h3 style="margin-top: 1em;">Email sent to <cfoutput>#session.authUser.getEmail()#</cfoutput></h3></cfoutput>
所有的数据是正确的,并在正确列,不过“Ship_Start”栏自带的格式相似,2012年11月27日00:00:00.000,并且无法在Excel中更改为任何其他格式。
如果我在SQL Server Management Studio中手动运行查询,然后将结果与标题复制到Excel,数据可以格式化。我还创建了一个Excel模板,其中的列标题格式化并使用数据填充模板,但即使使用“日期”格式化该列也无法格式化。
我可能会错过什么?
您运行的是哪种ColdFusion版本?你能格式化电子表格中的任何列吗?您是否尝试过使用[SpreadsheetFormatColumn](http://help.adobe.com/zh_CN/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6806.html)格式化列? –
这个应用程序驻留在CF9盒子上。我刚刚完成了SpreadsheetFormatColumn的测试,它会影响除“Ship_Start”之外的所有列。我注意到在Excel文件中,看起来像列中的数据后面有一个空格:“2012-11-27 00:00:00.0 ” – aparker81
我的问题已经添加了SpreadsheetFormatColumn更新。完整的CF版本是9,0,1,274733。 – aparker81