with newline inside OnExportCellFormatting" />

Change HeaderText & replace </br> with newline inside OnExportCellFormatting

6 posts, 1 answers
  1. Julian
    Julian avatar
    62 posts
    Member since:
    Apr 2015

    Posted 05 Jun 2015 Link to this post

    This seemed easy but I'm having trouble changing the HeaderText of a column inside of the OnExportCellFormatting event when exporting my grid to Excel.

     

    As an example I have a column with a headerText value of "11/2013</br>Actual" and I want to change change the </br> to a newline or CR  "/r/n" ? Whatever will make the header wrap and have "11/2013" above "Actual". Which is how it is displayed in the Grid.

    In my tests setting the headerText inside of the OnExportCellFormatting as below does not work.

    e.FormattedColumn.HeaderText = "New Header Text";

     

     

     

  2. Answer
    Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 10 Jun 2015 Link to this post

    Hi Julian,

    Could you please let me know which export format you are using? Note that OnExportCellFormatting event handler is fired only when using HTML based export format (default). Since this export format is based on an HTML the <br/> will be recognized by Excel and it will break the text after it. In case you are using some other format then you need to use another event to achieve the requested scenario.

    Regards,
    Kostadin
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Julian
    Julian avatar
    62 posts
    Member since:
    Apr 2015

    Posted 10 Jun 2015 in reply to Kostadin Link to this post

    Since i'm hitting OnExportCellFormatting then It must be HTML. I will retain the code as is and see then.I'll let you know thanks.
  4. Julian
    Julian avatar
    62 posts
    Member since:
    Apr 2015

    Posted 10 Jun 2015 in reply to Julian Link to this post

    It is most definitely not using the HTML tags. I am certainly hitting the OnExportCellFormatting as I stated in the header of this post. Please review the screen shot to see what the header text DOES look  like as compared to what the actual value is from the IDE at run time. I've put a watch in the IDE so you can see the headertext value for the column. (Ie. "11/2013</br>Actual").

     Also if you look at this code snippet I can change the HeaderText value on the export but it has no effect on the resultant excel file. I have a watch on the HeaderText and it gets changed after that line is executed. It becomes "Your Custom Text". So the real question here is.. and it's my original question. How do I change the HeaderText value of a column while inside the OnExportCellFormatting event? Can this be done.

     Code:

    protected void radGrid1_OnExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
           {
               //TODO: trying to this to see if it will allow me to changed the headertext of the column
               radGrid1.ExportSettings.IgnorePaging = true;
     
               var numStyles = NumberStyles.AllowParentheses | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
               var cellValue = string.Empty;
               var item = e.Cell.Parent as GridDataItem;
                
               //TODO: this align does not work //// use headerSTYLE
               //e.FormattedColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
     
               if (e.FormattedColumn.UniqueName.Length > 3)
               {
                   if ((e.FormattedColumn.UniqueName.Substring(0, 4) == "Plan") &&
                       (e.FormattedColumn.UniqueName.Substring(0, 6) != "Plan C")
                       || (e.FormattedColumn.UniqueName.Substring(0, 4) == "Actu"))
                   {
     
                       e.FormattedColumn.HeaderStyle.Width = Unit.Point(27);
                       var currentColumnName = e.FormattedColumn.UniqueName.ToString();
     
                       radGrid1.MasterTableView.GetColumn(currentColumnName).HeaderText = "Your Custom Text";

     

     I have to say I tire of Telerik's support. It's always.. "send me an example" or .. "it should" .. 

     I've given you the entire code before only to be told it was too complex to debug. LOL This is an EXTREMELY simple question. Can I change the headerText value of a column while inside the OnExportCellFormatting event. Also I've had  other issues where I did exactly what was told and it just didn't work. To then be told "I don't know try this or this". Support here is very poor in real world cases. Your examples are always the most simplistic and I"m sorry but in the real world who writes simple stuff like that. I work for the third largest manufacturing company in the world. I gaurantee you we will never have "simple" code. 

     

     

  5. Julian
    Julian avatar
    62 posts
    Member since:
    Apr 2015

    Posted 10 Jun 2015 in reply to Julian Link to this post

    Blah I fixed it. Forgive my irritation. *sticks head in sand*
  6. Julian
    Julian avatar
    62 posts
    Member since:
    Apr 2015

    Posted 10 Jun 2015 in reply to Julian Link to this post

    Blah I fixed it. Was a formatting issue. I still can't seem to affect the header text inside of the OnExportCellFormatting but changing the HTML tag slightly fixed it. 

     

    *sticks head in sand*

Back to Top