Free Support Forum - aspose.com

SQLDataReader and Excel DateTime formatting

I'm not sure if this is an Aspose or an Excel-specific question. Perhaps someone can help me, nonetheless.

On my development machine, I use the the Cells ImportFromDataReader method to import an MS SQL Server 2005 "datetime" value. When I open the Excel results file using my copy of Excel, the value is rendered as a Custom "m/d/yyy h:mm". This is good.

However, on a tester's machine running the same code and database schema (with different data), the Excel file renders as a General, so the date appears as a number.

I believe the tester is using Excel 2003 SP1 and I am using Excel 2003 SP2. Would this matter? Or is it an Excel configuration issue? Or might it be something with ImportFromDataReader?

Thanks for your help.

It doesn't matter with MS Excel.

When using ImportFromDataReader method, DateTime value is converted to number because MS Excel saves DateTime as number.

To make it show as DateTime value, you should set number format of those cells. You can use Style.Number or Style.Custom to set them.

When I open the Excel results file using my copy of Excel, the value is rendered as a Custom "m/d/yyy h:mm". Is this DateTime value before 1900/01/01? If yes, Aspose.Cells will render it as string so you cannot change the number format for that cell.

Could you post your two files here? I will check if my explanation suits the case.

Found the problem. It was our code.