Solved

ColdFusion  Receive an error when exporting date with excel spreadsheet function

Posted on 2014-03-26
5
533 Views
Last Modified: 2014-03-27
My Excel export function throws and error if there is no value for date:
'' is an invalid date or time string.

Formatting code:
<cfset SpreadsheetFormatColumn(sObj, {alignment="right", dataformat="mm/dd/yyyy"}, 21)>
0
Comment
Question by:DJPr0
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 39958052
The date/time will not get populated in cfspreadsheet if it is null, that is a bug as of now. all you have to do is use the CAST or convert function of sql to convert your datetime in varchar like the following example:

<cfquery name="myQueryDetails">
    	SELECT `ID`, `fname`, `lname`, `subject`, 
        CONVERT(`createddate`, CHAR(50)) as created 
        FROM mytable 
 <cfquery>

<!--- Make a spreadsheet object --->
<cfset s = spreadsheetNew()>
<!--- Add header row --->
<cfset spreadsheetAddRow(s, "Firstname,Lastname,Subject,CreatedOn")>
<!--- format header --->    
<cfset spreadsheetFormatRow(s, {bold=true, fgcolor="lemon_chiffon",fontsize=14}, 1)>
<!--- Add query --->
<cfset spreadsheetAddRows(s, myQueryDetails)>

<cfset filename = expandPath("myexcel.xls")>

<cfset spreadsheetWrite(s, filename, true)>



<!--- <cfset SpreadsheetFormatColumn(sObj, {alignment="right", dataformat="mm/dd/yyyy"}, 21)> --->

Open in new window

0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 39958053
I am making use of MYSQL Database, if any database let me know, i will add the query for that
0
 

Author Comment

by:DJPr0
ID: 39958848
Please convert query for an Access database.
0
 
LVL 16

Accepted Solution

by:
Gurpreet Singh Randhawa earned 500 total points
ID: 39959079
do it like this

CONVERT(varchar(10), [MyDateTimecolumn], 20)

http://msdn.microsoft.com/en-us/library/ms187928.aspx
0
 

Author Closing Comment

by:DJPr0
ID: 39959107
Thanks myselfrandhawa
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question