Unplanned
Last Updated: 20 Sep 2024 12:07 by Martin Ivanov
Martin Ivanov
Created on: 20 Sep 2024 12:07
Category: RichTextBox
Type: Bug Report
1
GridView: SpreadStreamExport exports DateTime objects as strings

Using the SpreadStreamExport feature of RadGridView doesn't work as expected when exporting DateTime objects. It exports the dates as String values which prevents the date-related features (like formatting) to work in Excel. 

To work this around, you can create a custom SpreadStreamExportRenderer and override its SetCellValue method. This will allow you to manually provide the DateTime object instead of the string.

  public class MyRenderer : SpreadStreamExportRenderer
  {
      public override void SetCellValue(DataType dataType, object value)
      {
          DateTime date;
          if (value != null && DateTime.TryParse(value.ToString(), out date))
          {
              base.SetCellValue(DataType.DateTime, date);
              var cell = this.GetCell() as ICellExporter;
              cell.SetFormat(new SpreadCellFormat() { NumberFormat = "yyyy-MM-dd HH:mm:ss" });
              return;
          }
          base.SetCellValue(dataType, value);
      }
  }


 spreadStreamExport.RunExportAsync(FILENAME, new MyRenderer(), options);

0 comments