Ticket T931106
Visible to All Users

How to set the format for dates when a document is exported to CSV

created 5 years ago

I have found only one option to change data format for export from XLS to CSV. This option is to specify CsvDocumentExporterOptions.Culture option.
But this option does not allow to override cell formating strings specified by a XLS author.

For example if for a cell with date a format string 'TT. MMM JJ' (dd. mmm yy) is specified, there is no way to export complete year like 2020, or month number instead of month name.

It would be nice to have possibility to specify own formating strings for exported data of different types.

Or maybe do you already have such possibility?

Answers approved by DevExpress Support

created 5 years ago

Hi Christian,
You can iterate through the cells in the data range (Worksheet.GetDataRange) and check whether a cell has a date value using the Cell.Value.IsDateTime property. If a cell stores the date value, change the date format using the Cell.NumberFormat property. This format will be used in the exported CSV file.
I hope that you will find this information helpful.

    Comments (2)
    CH CH
    Christian Hungbaur 4 years ago

      Thank you for your help. it works

      Maria Nikulina (DevExpress) 4 years ago

        You are welcome, Christian.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.