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

radgrid excel export remove column not work!

8 Answers 270 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JJ
Top achievements
Rank 1
JJ asked on 06 May 2011, 10:08 AM
I want to remove one column and also selected rows for excel export. Remove rows worked but remove column doesn't work.

I used e.Worksheet.Table.Columns.RemoveAt(3) under ExcelMLExportRowCreated to remove column (TagID) but doesn't work.

I can't make the TagID column invisible on the grid display because I need to use this TagID for checking when remove selected rows. .

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

 

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 rows worked

 

}

 

}

 

 

 

 

else

 

 

 

{

e.Worksheet.Table.Columns.RemoveAt(3); // want to remove TagID column from excel display (index id is 3) but didn't work

}


Please help!

8 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 May 2011, 09:52 PM
Hello JJ,

You can hide the desired column by setting the Hidden property of the ColumnElement to true. Otherwise you will have to remove not only the column element but the relevant cells also.
ExcelML structure / GridExcelBuilder

Please use the Code snippet tool (in the toolbox above) when you paste code in the forum thread.

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:30 PM
Under which evens after ExcelMLExportRowCreated that I can use the hidden preperty. I have to remove it under or after ExcelMLExportRowCreated  is triggered. Since I still need to use this column under ExcelMLExportRowCreated.

Thanks,
Jessie

 

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

You have to hide the column in the ExcelMLExportRowCreated event if you use pre-Q1 2011 version. A possible approach would be to check whether the current item is the last one so that you can hide the desired columns. Dummy code:
if(e.Worksheet.Table.Rows.Count == RadGrid1.Items.Count)
{
    foreach(ColumnElement col in ... )
    {
        col.Hidden = true;
    }
}

Note that this is just an example and not a runnable code - you will have to take the header row into consideration.

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 16 May 2011, 02:17 PM
Hi Daniel

I don't see the col (ColumnElement col) has  property "hidden"- pre-Q1 2011



0
Daniel
Telerik team
answered on 16 May 2011, 04:14 PM
Hello Jessie,

Just add the ss:Hidden attribute to the ColumnElement object as shown below:
colElement.Attributes.Add("ss:Hidden", "1");

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 16 May 2011, 04:40 PM
Works cool! Thanks Daniel.

0
Daniel
Telerik team
answered on 16 May 2011, 09:03 PM
Hello Jessie,

I'm glad that my suggestions were helpful to you. I would recommend that you bookmark the link below, it points to Microsoft's XMLSS documentation:
XML Spreadsheet Reference

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 16 May 2011, 09:08 PM
Thanks Daniel. This is helpful.

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