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

radgrid -can't remove column from excel export - please help

5 Answers 805 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JJ
Top achievements
Rank 1
JJ asked on 03 May 2011, 02:59 PM
I want to remove one column for excel export.

I used e.Worksheet.Table.Columns.Remove(3) under ExcelMLExportRowCreated but doesn't work.
I can't make the TagID column invisible on the grid display because I need to use this TagID to check -(!list.Contains(e.Row.Cells.GetCellByName("TagID").Data.DataItem.ToString())) if this TagID exists in the grid. I have to remove it after checking its existing.

-----------------------------------------------------------------------------------

 

if (!list.Contains(e.Row.Cells.GetCellByName("TagID"

).Data.DataItem.ToString()))

 

 

 

{

 

 

 

if (e.RowType == GridExportExcelMLRowType

.DataRow)

 

 

 

{

 

 

 

Int32

i = e.Worksheet.Table.Rows.Count;

 

 

 

e.Worksheet.Table.Rows.Remove(e.Row);

 

}

 

}

 

 

 

 

else

 

 

 

{

e.Worksheet.Table.Columns.RemoveAt(3); // want to remove TagID column for excel display but not working

}


Please help!

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 May 2011, 05:59 PM
Hello JJ,

I don't recommend that you go this route. Instead, you can hide the column before starting the export as demonstrated in the code-snippet below:
protected void Button1_Click(object sender, EventArgs e)
{
    RadGrid1.MasterTableView.GetColumn("ColumnName").Visible = false;
    RadGrid1.MasterTableView.ExportToExcel();
}

Please note that this change will be visible in the exported file only.
ExcelML basics

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
JJ
Top achievements
Rank 1
answered on 06 May 2011, 06:20 PM

Thanks for your reply.
I can not hide the column (TagID) before export to excel, because I need to use this column in the

 

ExcelMLExportRowCreated to checking if the TagID is checked, if it is not checked, this row needs to be removed.

 

So this have to happen after calling MasterTableView.ExportToExcel()

 

 

 

 

 

protected 

 

void rgTranslationView_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs

e)

 

{
if (!list.Contains(e.Row.Cells.GetCellByName("TagID"

).Data.DataItem.ToString()))

 

 

{

  

if (e.RowType == GridExportExcelMLRowType

.DataRow)

 {Int32

i = e.Worksheet.Table.Rows.Count;  

 

 

e.Worksheet.Table.Rows.Remove(e.Row);  // remove row whenTagID is in the checked list

 

 

 

}

 

 

 

}

 

 

 

 

else
{

 

 

e.Worksheet.Table.Columns.RemoveAt(3); // want to remove TagID column for excel display but not working

 

}

}


Please advice how I can remove this column after MasterTableView.ExportToExcel().

Thanks,
Jessie

0
Daniel
Telerik team
answered on 12 May 2011, 01:03 PM
Hello JJ,

You could hide the column by setting its Hidden property to true:

protected void RadGrid1_ExcelMLWorkBookCreated(object sender, GridExcelMLWorkBookCreatedEventArgs e)
{
    e.WorkBook.Worksheets[0].Table.Columns[2].Hidden = true;
}

ExcelML structure / GridExcelBuilder

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
JJ
Top achievements
Rank 1
answered on 13 May 2011, 03:15 PM
Hi Daniel,

I don't see  RadGrid1_ExcelMLWorkBookCreated evens under radgrid, only ExcelMLExportRowCreated and

ExcelMLExportStylesCreated

. I am using Q1 2010 NET35. So where should I put this piece of code?

Jessie

0
Daniel
Telerik team
answered on 16 May 2011, 11:41 AM
Hello Jessie,

Please go to the following thread:
Link to public post

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
JJ
Top achievements
Rank 1
Answers by
Daniel
Telerik team
JJ
Top achievements
Rank 1
Share this question
or