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 ...
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
0
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:
Hope this helps.
Regards,
Veselin Vasilev
the Telerik team
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
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
Hello,
Vlad
the Telerik team
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
Hi,
Didie
the Telerik team
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
Hello,
Didie
the Telerik team
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.
waiting for your reply
thank you.