从查询创建电子表格时,生成的电子表格将不允许格式化日期时间数据类型的列。
电子表格的创建是:
<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="noreply@pratt.com" 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 模板,其中列标题已格式化并用数据填充模板,但即使使用“日期”格式化该列也无法格式化。
我会错过什么?