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

RadGridView DataFormat Excel Export

10 Answers 241 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chad
Top achievements
Rank 1
Chad asked on 01 Oct 2010, 05:49 PM
I've got data loaded in the RadGridView control that I want to export to Excel. This is working just fine, using the .ToCSV method. However what I'm searching for is way to tell Excel to treat a column as a Text instead of General.

One of the columns is a bar code number. This number can start with a zero, like 0123456789.

After the export Excel cuts off the first zero because it is formatting it as a General and I get 123456789. I know I can reformat in Excel to custom format. But this should not be necessary.

Any recommendations?

I've tried setting DataFormatString to "{}{0:000000000000}", but this does not work. I did see a previous post that describes a bug in DataFormatString and I'm using 2010_1_0309 version of RadControls, which I think is a older version.

Thanks ...

10 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 07 Oct 2010, 12:57 PM
Hi Chad,

I found a way to cheat Excel so it will correctly show the numbers as text when they have leading zeroes. Please subscribe to the ElementExporting event and define its handler as follows:

private void gridView_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
    if (e.Element == ExportElement.Cell)
    {
        if ((e.Context as GridViewDataColumn).UniqueName == "Text")
        {
            e.Value = string.Format("=\"{0}\"", e.Value);  
        }              
    }
}

Hope this helps.

Regards,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chad
Top achievements
Rank 1
answered on 07 Oct 2010, 01:49 PM
Thanks for the recommendation, but this is not a ASP.net application. Sorry I should have provided those details, this is a WinForm WPF application that uses Model View View Model (see http://msdn.microsoft.com/en-us/magazine/dd419663.aspx) technique. So little to no code is in the XAML file, but a ViewModel.

I don't see a ElementExporting event available that I can subscribe to.

Any other ideas?

Thanks .... Chad
0
Chad
Top achievements
Rank 1
answered on 13 Oct 2010, 02:33 PM
Any additional recommendations?
0
Vlad
Telerik team
answered on 13 Oct 2010, 02:36 PM
Hello,

 Can you clarify if this is our RadGridView for Winforms or RadGridView for WPF? If this is the Winforms grid please post your questions in the relevant forum category. 

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
katie
Top achievements
Rank 1
answered on 26 Jul 2012, 01:55 PM
Has a solution for this been found for WPF? The leading zeros are being dropped when I export to Excel.
0
Dimitrina
Telerik team
answered on 26 Jul 2012, 01:58 PM
Hi,

 Please check this help article for further details.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
katie
Top achievements
Rank 1
answered on 26 Jul 2012, 02:11 PM
I do not have an 'ElementExporting' event. All I see is 'Exporting'.
0
Dimitrina
Telerik team
answered on 26 Jul 2012, 02:14 PM
Hello,

 It seems that you are not using the latest version of the RadControls for WPF.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
katie
Top achievements
Rank 1
answered on 26 Jul 2012, 02:19 PM
Indeed. That is why I replied to this post. I am almost positive it was created by a former co-worker. This is the exact same issue that I am having, with the exact same version. Do you have any suggestions that I could try, besides upgrading to the newest version?
0
Nikita
Top achievements
Rank 1
answered on 03 Aug 2012, 10:30 AM
I have hierarchy level RadGridView in wpf application. I want to export all level data in excel format. But it exports only first level data into excel.

waiting for your reply
thank you.
Tags
GridView
Asked by
Chad
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Chad
Top achievements
Rank 1
Vlad
Telerik team
katie
Top achievements
Rank 1
Dimitrina
Telerik team
Nikita
Top achievements
Rank 1
Share this question
or