我想將查詢導出到Excel文檔。ColdFusion電子表格錯誤,無效的日期或時間字符串
這裏是我使用的代碼:
<cfscript>
//Use an absolute path for the files. --->
theDir=GetDirectoryFromPath(GetCurrentTemplatePath());
theFile=theDir & "invoicesDue.xls";
//Create an empty ColdFusion spreadsheet object. --->
theSheet = SpreadsheetNew("invoicesData");
//Populate the object with a query. --->
SpreadsheetAddRows(theSheet,invoicesDue);
</cfscript>
<!--- Write the sheet to a file --->
<cfspreadsheet action="write" filename="#theFile#" name="theSheet" sheetname="invoicesDue" overwrite=true>
我得到的錯誤是:
'' is an invalid date or time string.
121: SpreadsheetAddRows(theSheet,invoicesDue);
的事情是,我已經甩了我的查詢,也沒有引號的任何地方以查看所有日期/時間單元格或者填入日期時間,例如「2011-03-31 00:00:00.0」或空字符串。
我想知道是否有其他人遇到過這個錯誤,因爲我看不到它的原因。
我相信錯誤消息顯示您確定的值無效。在這種情況下,''或空字符串。這並不是暗示價值中有引號。顯然,創建電子表格時,SpreadsheetAddRows函數不會像日期字段的空值。無論如何,這是我的猜測。是否有可能消除查詢中具有空日期字段的行,還是仍然需要電子表格中的行?在這種情況下,您可能需要某種方式爲這些空日期設置默認日期值。 –
爲什麼不直接將查詢直接提供給cfspreadsheet而不是將它傳遞給電子表格對象?應該爲你做所有的工作。 –
Busches
餵食查詢本身也沒有。有一些測試和@ Miguel-F是正確的,cfspreadsheet不喜歡日期字段的空值。最後我用'CAST(emptyDate as varchar)'這似乎是一個修復。謝謝。 – Alias