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

6 posts, 0 answers
  1. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 03 May 2011 Link to this post

    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!

  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 06 May 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 06 May 2011 Link to this post

    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

  5. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 12 May 2011 Link to this post

    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.

  6. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 13 May 2011 Link to this post

    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

  7. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 16 May 2011 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017