Declined
Last Updated: 22 Feb 2017 09:00 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 07 Apr 2016 08:18
Category: GridView
Type: Bug Report
1
FIX. RadGridView - SpreadExport does not respect the AM/PM time part with custom date format
To reproduce:

public class Item
{
    public int Id { get; set; }

    public string Name { get; set; }

    public DateTime Date { get; set; }

    public Item(int id, string name, DateTime date)
    {
        this.Id = id;
        this.Name = name;
        this.Date = date;
    }
}
public Form1()
{
    InitializeComponent();
    List<Item> items = new List<Item>();
    for (int i = 0; i < 10; i++)
    {
        items.Add(new Item(i,"Item" + i,DateTime.Now.AddHours(i)));
    }
    this.radGridView1.DataSource = items;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}

private void Form1_Load(object sender, EventArgs e)
{
    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB");
    this.radGridView1.Columns["Date"].ExcelExportFormatString = "M/d/yyyy h:mm tt";
    this.radGridView1.Columns["Date"].ExcelExportType = DisplayFormatType.Custom;

    GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
    spreadExporter.ExportVisualSettings = true;
    SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
    string fileName = @"..\..\exportedFile" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".xlsx";
    spreadExporter.RunExport(fileName, exportRenderer);
    Process.Start(fileName);
}

3 comments
ADMIN
Stefan
Posted on: 22 Feb 2017 09:00
Thanks for getting back to us Adam. Would you mind posting this issue on the AJAX portal so you can get appropriate help: https://feedback.telerik.com/Project/108 
Adam Nelson
Posted on: 20 Feb 2017 18:51
AM/PM doesnt work either though, it gets replaced with A(Month value)/P(Month value)

Sorry, I didnt notice this was a WinForms related post so I havent tested it under this scenario but I can say that AM/PM does not work with exporting from the grid in the UI Ajax library
ADMIN
Ivan Petrov
Posted on: 19 Jan 2017 13:08
The "tt" part of the format string is actually not a valid date time format in MS Excel. To get the am/pm part of the date time value one should replace "tt" with "AM/PM". In the following article, you can find more details on formatting in MS Excel ( https://support.office.com/en-us/article/Format-numbers-as-dates-or-times-418bd3fe-0577-47c8-8caa-b4d30c528309 section Hours, minutes, and seconds).