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";
5 Answers, 1 is accepted
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.
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.
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.
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*