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

Export to Excel in Radgrid

3 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sanjayanthan
Top achievements
Rank 1
sanjayanthan asked on 15 Apr 2010, 08:07 AM
Hi,

we are using Telerik product and Assembly  version
Product - 2009.02.0616.35
Assembly  2009.2.616.35

we use the below piece of code for exporting to excel from grid.But in the output, we face a empty row between the header and data rows in excel sheet.we don't want that empty row.

In one of the forums post they said to add this code RadGrid1.MasterTableView.AllowFilteringByColumn = false;
but still we dont have luck on that

 

void btnExcel_Click(object sender, ImageClickEventArgs e)

 

{

 

 

LRG RadGridToExport = this.Page.FindControl(RadGridIDToExport) as LRG;

 

 

if (RadGridToExport == null) return;

 

 

if (RadGridToExport.Items.Count > 0)

 {

RadGridToExport.ExportSettings.ExportOnlyData = 

true;

 

 

RadGridToExport.ExportSettings.IgnorePaging = chkAll.Checked;

RadGridToExport.ExportSettings.OpenInNewWindow = 

true;

 

RadGridToExport.MasterTableView.ExportToExcel();

}

}

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Apr 2010, 09:31 PM
Hello Sanjayanthan,

Try the following:

IgnorePaging="false"
protected void ExportButton_Click(object sender, EventArgs e)
{
    ...
    RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0].Visible = false;
    RadGrid1.MasterTableView.ExportToExcel();
}

IgnorePaging="true"
bool isExport = false;
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if(e.Item is GridFilteringItem && isExport)
}

protected void ExportButton_Click(object sender, EventArgs e)
{
    ...
    isExport = true;
    RadGrid1.MasterTableView.ExportToExcel();
}

Word/Excel export (HTML-based)

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
sanjayanthan
Top achievements
Rank 1
answered on 27 Apr 2010, 06:42 AM
Hi Daniel,

Thanks for your reply..

for IgnorePaging="false" as per your code  works fine.
But in our application we use moslty IgnorePaging="true".i have use the below code but no luck for me.
i have used code as below.  kindly suggests as what we have to give in radgrid_itemcreated event.need your help

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if(e.Item is GridFilteringItem && isExport)
{
e.Item.visible = false
}
}

your suggestion
bool isExport = false;
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if(e.Item is GridFilteringItem && isExport)
}

protected void ExportButton_Click(object sender, EventArgs e)
{
    ...
    isExport = true;
    RadGrid1.MasterTableView.ExportToExcel();
}
0
Daniel
Telerik team
answered on 27 Apr 2010, 09:16 PM
Hello Sanjayanthan,

You should set the flag when exporting (1) and then hide the item in ItemCreated/ItemDataBound (2):

(1) Set the flag and call the export method
protected void ExportButton_Click(object sender, EventArgs e)
{
    isExport = true;
    RadGrid1.MasterTableView.ExportToExcel();
}

Please note that if you export via the built-in buttons (residing in the commanditem) you should set the flag on ItemCommand instead on Button_Click.

(2) Hide the item on ItemCreated/ItemDataBound
protected  void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if(e.Item is GridFilteringItem && isExport)
        e.Item.Visible = false;
}

Of course, the flag should be declared globally:
using System.Data;
using Telerik.Web.UI;
 
public partial class _Default : System.Web.UI.Page
{
    bool isExport = false;
    ....

This code works flawlessly under normal circumstances. If the problem still persists, please attach a runnable project that demonstrates the problem and I will debug it locally.

Kind 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.
Tags
Grid
Asked by
sanjayanthan
Top achievements
Rank 1
Answers by
Daniel
Telerik team
sanjayanthan
Top achievements
Rank 1
Share this question
or