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

Excel Export, how to remove filter buttons etc...

4 Answers 765 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 23 Apr 2010, 05:57 PM
I am working on adding some excel export functionality to all of the grids in my application. I have played around with numerous options but I can't seem to get the results I need.

I have grids that use calculated columns and aggregates. When using the ExportDataOnly = true and Format="ExcelML" the calculated columns and aggregates do not appear on the export. Also, any formatting applied to data is lost.

When I set ExportDataOnly = false and use HTML format the column names are linked inside of excel, the filter fields appear, and all hell breaks loose when you have a detail table.

I've tried using the GridExporting event like this:

        protected void RadGridSearch_GridExporting(object source, GridExportingArgs e) 
        { 
            RadGridSearch.AllowSorting = false
            RadGridSearch.AllowFilteringByColumn = false
        } 

It does not seem to change the export behavior.

I need to be able to do one of 2 things, either have my aggregated data and calculated columns show up on data only exports, or be able to trim out all the extra garbage when using HTML format.

Any suggestions?


4 Answers, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 23 Apr 2010, 06:19 PM
I did manage to make something happen, although it was undesired.

Using this code:

protected void ImageButtonExcelExport_Click(object sender, System.Web.UI.ImageClickEventArgs e) 
        { 
            RadGridSearch.MasterTableView.AllowFilteringByColumn = false
            RadGridSearch.MasterTableView.AllowSorting = false
            RadGridSearch.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; 
 
            RadGridSearch.Rebind(); 
            RadGridSearch.MasterTableView.ExportToExcel(); 
        } 

I can get the column headers to show up as text, and the buttons disappear, BUT, since I have disabled sorting and filtering, sorts and filters used on the Grid are not reflected in the export data.

I guess what I really need is for calculated and aggregates to show up when the show only data option is selected. Additionally on most grids I use the command buttons and I don't have an event hander for each page as this would add an enormous amount of unreusable code to my application.
0
James
Top achievements
Rank 1
answered on 28 Apr 2010, 03:06 PM
No ideas on this yet?  All I need to do is export the entire grid to Excel without the sort links or buttons.
0
Daniel
Telerik team
answered on 28 Apr 2010, 06:42 PM
Hello James,

Issue 1: How to export RadGrid without the filter item (HTML Excel, ExportOnlyData="false")

When IgnorePaging is set to "false" you can use this approach:
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridFilteringItem item in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
        item.Visible = false;
    RadGrid1.MasterTableView.ExportToExcel();
}

This will work with IgnorePaging="true":
bool isExport = false;
protected void Button1_Click(object sender, EventArgs e)
{
    isExport = true;
    RadGrid1.MasterTableView.ExportToExcel();
}
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (isExport && e.Item is GridFilteringItem)
        e.Item.Visible = false;
}


Issue 2: How to export RadGrid along with the aggregates and the calculated columns (ExcelML)
RadGrid's ExcelML engine fetches the data directly from the data source - all non-data rows/columns like footer aggregates and calculated columns will be ignored.
In fact, you can add the missing items manually, but this will require some coding - this is demonstred in the attached project.

Best regards,
Daniel
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Josef Rogovsky
Top achievements
Rank 2
answered on 04 Apr 2017, 10:32 PM
Thanks. This was helpful.
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Daniel
Telerik team
Josef Rogovsky
Top achievements
Rank 2
Share this question
or