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

Export to Excel and CSV for MultiColumn Headers in RadGrid

4 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kranthi kiran pusala
Top achievements
Rank 1
kranthi kiran pusala asked on 18 Sep 2013, 06:46 PM
I am creating a RadGrid Dynamically in code behind based on a DataSet returned from a Stored Procedure. I have enabled Export to Excel, CSV and PDF Options.
The Exported Excel and CSV is missing the Multi-column headers. The PDF Export retains the Multi-Colum Headers.

I am using  ExcelML format while exporting to Excel. However when I use HTML format, Its showing Multi-Column Headers, but the export also contains hyperlinks ( in rows related to data and the column titles) and additional  controls( related to filter I guess). I have also used the setting ExportOnlyData to true.

Is there a way to remove the hyperlinks and additional controls. Also, Is there a way I could get the Multi-Column Headers in CSV.

Thanks,
Kiran

4 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 23 Sep 2013, 08:58 AM
Hi Kiran,

I am afraid that the CSV does not support multi-column header but since the CSV format is a plain text you could manually build one by looping through all header items and all data items and save them in a StringBuilder. As to the Excel export I was not able to reproduce the issue when ExportOnlyData is set to true. Could you please confirm that you are enabling this property when exporting to excel?

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
TonyG
Top achievements
Rank 1
answered on 26 Mar 2015, 12:27 AM
[quote]CSV does not support multi-column header[/quote]
Has there been any change to this since Q2 2013? I'm being asked to CSV-export a grid with multi-column headers, and I'm hoping to get the parent headers repeated in child header fields, So where the group is called "Monday" and there are two columns under that, like "Morning" and "Evening", I want to have a single CSV cell with "Monday Morning" and the next as "Monday Evening".

[quote]since the CSV format is a plain text you could manually build one by looping through all header items and all data items and save them in a StringBuilder[/quote]
I've been trying to do this in the grid_ItemCreated and grid_GridExporting events. I can hack away at the string in GridExportingArgs.ExportOutput, but I'm hoping there is a more elegant place to modify the strings further up the event chain. In ItemCreated I'd like to be able to modify the column headers with the GridHeaderItem.MultiHeaderCells.GridColumnGroup[] elements, but that's not exposed. Do I need to reach up into the grid.MasterTableView.ColumnGroups somewhere in the event chain to get and modify column names? Guidance is welcome.

Thanks!
0
TonyG
Top achievements
Rank 1
answered on 26 Mar 2015, 12:28 AM
[quote]CSV does not support multi-column header[/quote]
Has there been any change to this since Q2 2013? I'm being asked to CSV-export a grid with multi-column headers, and I'm hoping to get the parent headersrepeated in child header fields, So where the group is called "Monday" and there are two columns under that, like "Morning" and "Evening", I want to have a single CSV cell with "Monday Morning" and the next as "Monday Evening".

[quote]since the CSV format is a plain text you could manually build one by looping through all header items and all data items and save them in a StringBuilder[/quote]
I've been trying to do this in the grid_ItemCreated and grid_GridExporting events. I can hack away at the string in GridExportingArgs.ExportOutput, but I'm hoping there is a more elegant place to modify the strings further up the event chain. In ItemCreated I'd like to be able to modify the column headers with the GridHeaderItem.MultiHeaderCells.GridColumnGroup[] elements, but that's not exposed. Do I need to reach up into the grid.MasterTableView.ColumnGroups somewhere in the event chain to get and modify column names? Guidance is welcome.

Thanks!
0
Kostadin
Telerik team
answered on 30 Mar 2015, 11:37 AM
Hello Tony,

The easiest way is to modify the exported output on GridExporting event handler otherwise you have to loop though all grid items and build the exported text. You can get the header items values by using the following approach.
GridItem[] headerItems = RadGrid1.MasterTableView.GetItems(GridItemType.Header);
foreach (GridHeaderItem header in headerItems)
{
    for (int i = 0; i < header.Cells.Count; i++)
    {
        string text = header.Cells[i].Text;
    }
}


Regards,
Kostadin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
kranthi kiran pusala
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
TonyG
Top achievements
Rank 1
Share this question
or