DATETIME Column problem

Hi,


I export data from database to xlsx. The export query is a dynamic query. So, I don’t know which columns are datetime type. When I export the data, in the excel the datetime columns shown like integer value. Is it possible to determine which columns are datetime to set this field style number as datetime field number automaticly?

Thank you.

Hi,


Well, by default, DateTime values are stored in numeric notations in MS Excel. If you are importing data from some source using ImportDataTable() method, then you may use some suitable overloads for your requirements, see the sample lines of code segment for your reference. I provided the DateTime formatting string for the last parameter in the method, you may specify your desired formatting accordingly.

e.g
worksheet.Cells.ImportDataTable(dataTable, true, 0, 0, dataTable.Rows.Count, dataTable.Columns.Count, true, “MMM-dd-yyyy”);
worksheet.AutoFitColumns();

Thank you.

Hi again,


Thanks for the reply. But this like of usage ImportDataTable does not resolve my problem. It shows the datetime column numeric again.

Oh sorry, my fault. The code works perfectly for me now.

Hi,


No problem and good to know it works for you now.

Feel free to contact us any time if you have further query or have some other issue, we will be happy to assist you soon.

Thank you.