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

Problem with header names when exporting to Excel

2 Answers 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 13 Feb 2015, 06:22 PM
I've been using the RadGrid's ExportToExcel function and I have one problem.

The setup is very simple.  The grid has only one option:    <Excel Format="Biff"/>

The dataset has field names like DocId and ClientID.  

When the Excel is created it's inserting spaces into the column headers (Doc ID, Client ID, etc).  

I'd like to prevent that.  So far I can't find any code that works.  

Suggestions?  (Haven't been able to get events like BiffExporting or ExcelExportCellFormatting to do anything.)

2 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 18 Feb 2015, 11:36 AM
Hi Boris,

The text in the column headers in the exported file is set based on the HeaderText property of a column. Try to modify the string in the HeaderText property so that there are no spaces and the same text would be exported to Excel.

For example:

<telerik:GridBoundColumn DataField="ClientID" HeaderText="ClientID" UniqueName="ClientID">
</telerik:GridBoundColumn>



Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Boris
Top achievements
Rank 1
answered on 18 Feb 2015, 03:02 PM
I'm going to make an embarrassing admission.  I had the solution the whole time but for the specific condition I needed, it wasn't firing.  I'll keep Viktor's solution in mind for future use but unfortunately it doesn't exactly apply to my situation.  The thing is that for my needs, this RadGrid has very little code, is un-formatted and relies on auto-generation of columns at run-time to simplify matters (since it must display multiple different data sets depending on use).  All I'm doing is hooking the grid to a data source.

The real solution for my problem was as follows.  At the top of the ItemDataBound event handler:

   if (e.Item is GridHeaderItem)
   {
           GridHeaderItem headerItem = (GridHeaderItem)e.Item;
           foreach (GridTableHeaderCell c in headerItem.Cells)
                   c.Text = c.Text.Replace(" ", string.Empty);              
   }

But thanks for the learning experience.


Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Boris
Top achievements
Rank 1
Share this question
or