Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
How to export correct DateTime to excel?
posted

hi,
  I exported UltraGrid data to excel file. UltraGrid contains 3 columns containing datetime. One is short date such as 22/4/2009,the other two are long time such as 18:00:00. I wrote this code to export to excel file: me.UltraGridExcelExporter1.Export(me.UltraGrid1,"C:\\test.xls")
when I open the excel file, the date column will show as "22/4/2009 12:00:00", and the time column will show as "1/0/1900 18:00:00".
 
  what should I do to make this correct?

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    There's no such thing as a short date data type in DotNet. So what you probably have in your grid is a column of DateTime objects and either you or the grid is formatting the column to just show the date.

    When you export to Excel, the DotNet date formats are not the same as the ones in Excel, so the grid cannot export the format along with the data. The UltraGridExcelExporter has an event called InitializeColumn to allow you to get the format from the grid column and apply an appropriate format to the Excel cells. A lot of the time you can simply set the ExcelFormatStr to the grid's format string.

Children