Export to Excel hidden columns

11 posts, 0 answers
  1. Dario Zanelli
    Dario Zanelli avatar
    40 posts
    Member since:
    Dec 2009

    Posted 12 Feb 2010 Link to this post

    Hi all!
    I need to export to an excel file the content of my RadGrid.
    The exporting is working fine, but I have some hidden columns that aren't exported.
    I have tried like follows to make visible those columns, but it doesn't work. If I make not visible a column that is visible instead it is working.

            protected void mngBtnExcel_Click(Object sender, EventArgs e)
            {
                this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Visible = true;
                this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Visible = true;
                this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Visible = false;

                this.grdRcm.ExportSettings.ExportOnlyData = true;
                this.grdRcm.ExportSettings.IgnorePaging = true;
                this.grdRcm.ExportSettings.OpenInNewWindow = true;
                this.grdRcm.MasterTableView.ExportToExcel();

                this.grdRcm.MasterTableView.GetColumn("Process").Visible = false;
                this.grdRcm.MasterTableView.GetColumn("SubprocessDescr").Visible = false;
            }

    The columns "Process" nad "SubProcessDescr" are not visible, but I need to export them.
    Thanks and best regards.

    Dario
  2. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 12 Feb 2010 Link to this post

    Whenever you hide/unhide columns the best property to use would be "Display" as opposed to "Visible". The Display properly simply changes the style while the Visible can be used if you wish to not render the columns. I think if you replace all of your visible's with display this might help you.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dario Zanelli
    Dario Zanelli avatar
    40 posts
    Member since:
    Dec 2009

    Posted 15 Feb 2010 Link to this post

    Hi Schlurk!
    Thanks for your answer. I tried but it doesn't work. Here there is my code:

    protected void mngBtnExcel_Click(Object sender, EventArgs e)
    {
        this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Display = true;
        this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Display = true;
        this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Display = false;

        this.grdRcm.ExportSettings.ExportOnlyData = true;
        this.grdRcm.ExportSettings.IgnorePaging = true;
        this.grdRcm.ExportSettings.OpenInNewWindow = true;
        this.grdRcm.MasterTableView.ExportToExcel();

        this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Display = false;
        this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Display = false;
        this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Display = true;
    }

    The resulting file doesn't show the columns "Process" and "SubprocessDescr" and shows the "EditCommandColumn"

    Is there another way to select the columns that I need?


    Best regards,

    Dario Zanelli






  5. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 17 Feb 2010 Link to this post

    Hello Dario,

    You shouldn't have to change the state of the columns after exporting since this code will affect the exported file only. Please try the following approach:
    protected void mngBtnExcel_Click(Object sender, EventArgs e)
    {
        this.grdRcm.MasterTableView.GetColumn("Process").Display = true;
        this.grdRcm.MasterTableView.GetColumn("SubprocessDescr").Display = true;
        this.grdRcm.MasterTableView.GetColumn("EditCommandColumn").Display = false;
     
        this.grdRcm.ExportSettings.ExportOnlyData = true;
        this.grdRcm.ExportSettings.IgnorePaging = true;
        this.grdRcm.ExportSettings.OpenInNewWindow = true;
        this.grdRcm.MasterTableView.ExportToExcel();
    }

    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.
  6. Amy Liu
    Amy Liu avatar
    28 posts
    Member since:
    Dec 2009

    Posted 26 Aug 2011 Link to this post

    Hello!
    A simple question: I used the image in the grid. How can I put the code in the image click event?
    I used GridExporting event and put the display=true code inside. It seem to me that it doesn't work.
     Is it a click event also ? where?

    Thanks.

    Amy
  7. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 31 Aug 2011 Link to this post

    Hello Amy,

    I suppose you mean that you export the control via the built-in image buttons. If this is so, I would recommend that you hide/show the desired columns within the ItemCommand event when e.CommandName is equal to "ExportToExcel".

    Best regards,
    Daniel
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  8. Steele
    Steele avatar
    96 posts
    Member since:
    Mar 2008

    Posted 08 Sep 2011 Link to this post

    Hi Daniel,
    I too am handling this scenario - using the default Export button in the Command item for the grid.
    Following your final advice of changing the Display of the columns in the ItemCommand event, I have found that this affects the Grid when it is refreshed.  Basically, the columns to be shown only in the export get shown to the grid in the page.
    This is undesireable.
    I have tried to change the Display property in the radgrids GridExporting event, but it seems that this is too late in the cycle, as none of the changes take affect in the resulting Excel document.
    Any tips on when to re-hide the columns??
    Thanks,
    Steele.
  9. Steele
    Steele avatar
    96 posts
    Member since:
    Mar 2008

    Posted 09 Sep 2011 Link to this post

    Just thought I'd put up my work around for this. Though it does seem a little clunky.
    void rg_ItemCommand(object sender, GridCommandEventArgs e)
            {
                if (e.CommandName == "ExportToExcel")
                {
                    RadGrid rg = (RadGrid)sender;
                    rg.MasterTableView.GetColumn("CountOfRespDone").Display = true;
                    rg.MasterTableView.GetColumn("TotalOfResp").Display = true;
                    rg.MasterTableView.GetColumn("RespToDo").Display = true;
     
                }
            }

    Now if this is left as is, the columns become visible once the grid is refreshed, so we fix this up in the prerender :
    void rg_PreRender(object sender, EventArgs e)
    {
        RadGrid rg = (RadGrid)sender;
        rg.MasterTableView.GetColumn("CountOfRespDone").Display = false;
        rg.MasterTableView.GetColumn("TotalOfResp").Display = false;
        rg.MasterTableView.GetColumn("RespToDo").Display = false;
     
        rg.ClientSettings.Scrolling.UseStaticHeaders = true;
    }

    You can see that I am setting UseStaticHeaders to true here.  My grid has this value set on creation, but it gets lost after the export has occurred.  Is this a bug??

    Hope this helps.


  10. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 14 Sep 2011 Link to this post

    Hello Steele,

    I'm unable to recreate this scenario. Please download the attached demo and see what is missing. I would appreciate it, if you could modify this project to help me reproduce the problem.

    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
  11. Ramprit
    Ramprit avatar
    3 posts
    Member since:
    Feb 2015

    Posted 22 Apr 2015 in reply to Daniel Link to this post

    Export to excel in radgrid but there without using CommandItemDisplay="Top" i am not able to see export button when i use CommandItemDisplay="Top" than it show Edit on left side on the top side i have not req- that how to hide this please help me.....
  12. chetna
    chetna avatar
    1 posts
    Member since:
    Sep 2016

    Posted 19 Sep in reply to Dario Zanelli Link to this post

    Thank u so much for your Answer , It works !!!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017