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

ExportToExcelML exception with null date

3 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 06 Apr 2011, 10:33 PM
Hi,

I have a radgridview with a column that's bound to a nullable date.   When the date is null, the RunExport() method throws a FormatException with the message "The DateTime value is not supported in Excel!".   Do you have any thoughts on how I can handle this issue?

Thanks,
Kevin.

3 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 07 Apr 2011, 07:53 AM
Hello Kevin,

Sadly i could not reproduce this issue. I'm using the latest version q1 2011.
Please try to run the following example:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Export;
 
public partial class Form1 : Form
{
    private RadGridView radGridView1;
    private List<User> users;
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(radGridView1 = new RadGridView());
        radGridView1.Dock = DockStyle.Fill;
        radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
        users = new List<User>();
        for (int i = 0; i < 10; i++)
        {
            var user = new User
            {
                Id = i,
                Name = "Name" + i,
                Details = "Bla bla bla " + i
            };
            users.Add(user);
 
            if (i % 2 == 0)
            {
                user.Date = DateTime.Now.AddMonths(i);
            }
        }
 
        radGridView1.DataSource = users;
 
        var button = new RadButton();
        button.Text = "Export me!";
        button.Click += new EventHandler(button_Click);
        button.Dock = DockStyle.Bottom;
        this.Controls.Add(button);
    }
 
    void button_Click(object sender, EventArgs e)
    {
        var exporter = new ExportToExcelML(this.radGridView1);
        exporter.ExportVisualSettings = true;
        exporter.SheetMaxRows = ExcelMaxRows._1048576;
        exporter.SheetName = "Sheet";
        string fileName = "C:\\ExportedData123.xls";
        this.radGridView1.Columns["Date"].ExcelExportType = DisplayFormatType.ShortDate;
        // or for custom formats
        // this.radGridView1.Columns["Date"].ExcelExportType = DisplayFormatType.Custom;
        // this.radGridView1.Columns["Date"].ExcelExportFormatString = "dddd, dd.MM.yyyy";
        exporter.RunExport(fileName);
    }
}
 
public class User
{
    public int Id
    {
        get;
        set;
    }
 
    public string Name
    {
        get;
        set;
    }
 
    public string Details
    {
        get;
        set;
    }
 
    public DateTime? Date
    {
        get;
        set;
    }
}

If you still have some issues, please let me know.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Kevin
Top achievements
Rank 1
answered on 25 Apr 2011, 06:16 PM
Hi Emanuel,

sorry for the delay in my reply and thanks for the example!   The issue turned out to be a coding issue on my end - the date time object was ending up only having a time component only.  Once I changed it to have a valid Date/Time, everything worked great.

Thanks,
Kevin.
0
Emanuel Varga
Top achievements
Rank 1
answered on 29 Apr 2011, 11:16 AM
Hello,

Sorry for the very late response, but glad to be able to help,

If you have any more questions please just let me know, and if the question has been solved, please mark the question as answered, so that others can find the answers to their questions faster.

Best Regards,
Emanuel Varga

WinForms MVP
Tags
GridView
Asked by
Kevin
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Kevin
Top achievements
Rank 1
Share this question
or