ExportColumnSettings date format issue

1 Answer 25 Views
Grid Spreadsheet
Saranya
Top achievements
Rank 1
Saranya asked on 07 May 2025, 08:57 AM
i have sample application. when export to excel using ToXlsxStream date field show as number value instead of date . 

1 Answer, 1 is accepted

Sort by
0
Ivaylo
Telerik team
answered on 12 May 2025, 06:52 AM

Hi Saranya,

Thank you for the details provided.

To format the date within a cell, you can apply the NumberFormat property to the SpreadCellFormat object within the ChangeCellStyle method. This method accepts an ExportCellStyle object as its parameter. To ensure that the formatting is applied exclusively to the date column, you can utilize the Column property of the ExportCellStyle parameter, which indicates the index of the current column. For instance, if the value of the Column property is 2, it corresponds to the date column; otherwise, it refers to other columns.

Below is an example implementation:

private void ChangeCellStyle(ExportCellStyle e)
{
    bool isHeader = e.Row == 0;
    SpreadCellFormat format = new SpreadCellFormat
    {
        ForeColor = isHeader ? SpreadThemableColor.FromRgb(255, 255, 255) : SpreadThemableColor.FromRgb(0, 0, 0),
        IsItalic = true,
        IsBold = isHeader,
        VerticalAlignment = SpreadVerticalAlignment.Center,
        WrapText = true,
        Fill = SpreadPatternFill.CreateSolidFill(isHeader ? new SpreadColor(0, 0, 0) : new SpreadColor(255, 255, 255)),
        NumberFormat = e.Column == 2 ? "yyyy/MM/dd" : ""
    };

    e.Cell.SetFormat(format);
}

Furthermore, I prepared a sample application where the suggested modification could be tested.

I hope this information was helpful.

Kind Regards,
Ivaylo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid Spreadsheet
Asked by
Saranya
Top achievements
Rank 1
Answers by
Ivaylo
Telerik team
Share this question
or