This is a migrated thread and some comments may be shown as answers.

Dates formatted as general in exported file

1 Answer 213 Views
SpreadStreamProcessing
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 1
B asked on 13 Feb 2019, 10:19 PM
When I'm exporting a file that has dates, the format is coming across as general instead date.  When I inspect the column data deserialized from the model object it is indeed showing a date format, it just doesn't seem to be applied when the workbook is created.  Any suggestions?

1 Answer, 1 is accepted

Sort by
0
Nikolay Demirev
Telerik team
answered on 18 Feb 2019, 11:08 AM
Hello B Smith,

The RadSpreadStreamProcessing exports only the data which is given. It does not "understand" that it is a Date value in order to apply a number format. In order to export cell values formatted as Date, you have to set the cell format too. Here is an example:
using (FileStream stream = File.Open(fileName, FileMode.OpenOrCreate))
{
    using (IWorkbookExporter workbook = SpreadExporter.CreateWorkbookExporter(documentFormat, stream))
    {
        using (IWorksheetExporter worksheet = workbook.CreateWorksheetExporter("Date"))
        {
            using (IRowExporter row = worksheet.CreateRowExporter())
            {
                using (ICellExporter cell = row.CreateCellExporter())
                {
                    cell.SetValue(DateTime.Now);
                    cell.SetFormat(new SpreadCellFormat() { NumberFormat = "m/d/yyyy" });
                }
            }
        }
 
    }
}

I hope the provided information was helpful.

Regards,
Nikolay Demirev
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
SpreadStreamProcessing
Asked by
B
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Share this question
or