ColdFusion电子表格错误,无效的日期或时间字符串

时间:2013-01-17 10:46:42

标签: date coldfusion spreadsheet export-to-excel coldfusion-10

我正在尝试将查询导出到Excel文档。

以下是我正在使用的代码:

<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); 

问题是,我已经抛弃了我的查询,并且没有任何引号可供查看,并且所有日期/时间单元格都填充了日期时间,例如&#34; 2011-03-31 00:00 :00.0&#34;或空字符串。

我想知道是否有其他人遇到过这个错误,因为我无法看到它的原因。

2 个答案:

答案 0 :(得分:2)

cfspreadsheet不喜欢日期字段的空值。最后我用了:

CAST(emptyDate as varchar) 

这似乎是一个修复。

答案 1 :(得分:0)

作为替代方案,我使用Ben Nadel的queryToCSV() function并绕过cfspreadsheet的“怪癖”。当我只需要一个单页的csv / xls文件时,它就像一个魅力。