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

8 posts, 0 answers
  1. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 10 Aug 2011 Link to this post

    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
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 11 Aug 2011 Link to this post

    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 >>
  3. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 08 Dec 2011 Link to this post

    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
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 13 Dec 2011 Link to this post

    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 >>
  5. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 15 Dec 2011 Link to this post

    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

  6. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 27 Dec 2011 Link to this post

    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
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Dec 2011 Link to this post

    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 >>

  8. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 28 Dec 2011 Link to this post

    Thank you that really worked!

    Amit
Back to Top