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

Exporting to excel references control name, not the actual column name

7 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amit Patel
Top achievements
Rank 1
Amit Patel asked on 10 Aug 2011, 06:29 PM
Hello

When I export a grid to excel file  and open it up, I see control names, not the actual column name that I specified. How can i fix this?

Thanks,
Amit

7 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 11 Aug 2011, 08:45 AM
Hello Amit Patel,

In order to provide more flexibility for our clients, we have defined the columns' Header property to be of type object. However, when exporting a HeaderCell element, our exporting mechanism calls ToString() on Header's value. Please, refer to the attached project for some more extensive info.

Regards,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Amit Patel
Top achievements
Rank 1
answered on 08 Dec 2011, 09:31 PM
Hello,
I have been meaning to come back to ask more questions about this issue, and finally i got a chance. There are areas in our application where we have to give a column a name dynamically, and to do that we create a new TextBlock and sticking it to header. Since header property of column returns as an object, there is really nothing to set to except to get it a new instance of some control. I was wondering is there any other sophisticated way to give a column a name, so when grid is exported to excel, actual column name are displayed. The solution you provided in your previous post will work in a situation where, I know my column names in advance and set them in xaml .

Thanks,
Amit
0
Ivan Ivanov
Telerik team
answered on 13 Dec 2011, 02:48 PM
Hello Amit Patel,

Please excuse me for my previous post as it might have been a bit confusing because of my limited information on your requirements. From your first post I was left with the impression that you might be using some complex content for your header cells, but you have mentioned that you are using TextBlock. Would you please confirm whether it is an option for you to set columns' headers as strings? Then you won't experience such an issue.

Regards,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Amit Patel
Top achievements
Rank 1
answered on 15 Dec 2011, 03:41 PM

Thanks for responding to my questions!

All of header names are localized, and get its name during run time. We have a framework in place that sets the header name at run time. Therefore, we have to use text block to set header names. Don't think setting a string would be possible here.


here is code snippet that sets name.

if (IsNullOrString(column.Header)) 
{
// Column UniqueName matches resource display string...
var textBlock = new TextBlock() { TextWrapping = TextWrapping.Wrap, };
if
 (BindProperty(textBlock, TextBlock.TextProperty, viewModel, column.UniqueName + "Text"))
{
column.Header = textBlock; textBlock.DataContext = viewModel;
}
else

{
string headerText = DisplayStringProvider.GetDisplayString(viewModel, column.UniqueName);
if (headerText != null)
{
textBlock.Text = headerText; column.Header = textBlock;
}
}
}

Thanks,
Amit

0
Amit Patel
Top achievements
Rank 1
answered on 27 Dec 2011, 04:19 PM
Hi Ivan,
Can you respond my previous post? If there there is no way to achive this, can you add this to your feature request list?

Thanks,
Amit
0
Dimitrina
Telerik team
answered on 28 Dec 2011, 01:01 PM
Hi Amit,

 If you have a custom header and your Header text is in a TextBlock, then you should check the solution explained in this help article.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Amit Patel
Top achievements
Rank 1
answered on 28 Dec 2011, 03:29 PM
Thank you that really worked!

Amit
Tags
GridView
Asked by
Amit Patel
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Amit Patel
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or