從查詢創建電子表格時,生成的電子表格不允許格式化某個日期時間數據類型的列。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