Radgrid export to excel, hide column in excel

9 posts, 0 answers
  1. Bouyez
    Bouyez avatar
    14 posts
    Member since:
    Jan 2017

    Posted 16 Jan 2017 Link to this post

    Hi, 

    When I export my grid to an excel file (ExcelML), I need to hide some column in this excel file (same as when you hide a column in excel). How can I do that?

    Thx.

  2. Rumen
    Admin
    Rumen avatar
    14075 posts

    Posted 16 Jan 2017 Link to this post

    Hello Bouyez,

    You can find solution for your question in the following community threads:

    http://www.telerik.com/forums/hide-columns-before-export-to-excel 

    http://www.telerik.com/forums/export-to-excel-hidden-columns

    http://www.telerik.com/forums/radgrid--can-t-remove-column-from-excel-export---please-help

    Regards,
    Rumen
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Bouyez
    Bouyez avatar
    14 posts
    Member since:
    Jan 2017

    Posted 18 Jan 2017 Link to this post

    Thx,

    My project's constraint about Excel export change, now I export in Xlsx format. But I didn't find how I can catch the created workbook like "OnExcelMLWorkBookCreated" to hide column in my excel file.

    Jordan.

  4. Rumen
    Admin
    Rumen avatar
    14075 posts

    Posted 20 Jan 2017 Link to this post

    Hello Jordan,

    If you set Exportable property of the column to false, it won't be exported.

    Another way is to handle the ItemCommand event and to hide the column by setting Visible=false. After that the grid should be rebinded and you have to call ExportToExcel().

    If your scenario is other please provide more detail about it.

    Regards,
    Rumen
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Bouyez
    Bouyez avatar
    14 posts
    Member since:
    Jan 2017

    Posted 24 Jan 2017 Link to this post

    Hi Rumen,

    i don't have issue to hide a column in radgrid, I need to get the hidden column in my excel file but with a  width of 0 (hide)

    If I set my column to exportable = true / display = false , I still don't have the column. I think I must change de width of the excell column instead of trying to auto hide it. 

    I found that I can do that by doing something like this : Worksheet.get_Range("C:C", missing).EntireColumn.Hidden = true

    How can I have access to the workbook before it was exported?

     

  6. Bouyez
    Bouyez avatar
    14 posts
    Member since:
    Jan 2017

    Posted 27 Jan 2017 in reply to Bouyez Link to this post

    With the folling code I can do some style/format manipulation

    protected void RadGridEdit_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
            {
                DateTime dateValue;
                e.ExportStructure.Tables[0].Style.Font.Size = FontUnit.Point(8);
                foreach (Telerik.Web.UI.ExportInfrastructure.Row row in e.ExportStructure.Tables[0].Rows)
                {
                    foreach (Telerik.Web.UI.ExportInfrastructure.Cell cell in row.Cells)
                    {
                        if (DateTime.TryParse(cell.Text, out dateValue))
                        {
                            cell.Format = @"mm/dd/yyyy hh:mm:ss AM/PM";
                            cell.Value = dateValue.ToString();
                        }
                    }
                }
            }

    I tried to do something like this :

    foreach (Telerik.Web.UI.ExportInfrastructure.Column col in e.ExportStructure.Tables[0].Columns)
                {
                    col.Width = 0;
                }

     

    But nothing change 

  7. Rumen
    Admin
    Rumen avatar
    14075 posts

    Posted 31 Jan 2017 Link to this post

    Hello Bouyez,

    If you'd like to hide a column in Excel, you could try to generate the excel file with RadSpreadProcessing and hide the column with its hidden property.

    Regards,
    Rumen
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  8. Bouyez
    Bouyez avatar
    14 posts
    Member since:
    Jan 2017

    Posted 08 Feb 2017 Link to this post

    Hello Rumen,

    Unfortunatly, my team leader still want to use the default excel generator of the grid. I found a way by setting the width of the GridColumn with 1px value (0 hide it ...). 

    I have a new issue with the excel file:

    I change the font size: ExportStructure.Tables[0].Style.Font.Size = FontUnit.Point(8);

    But in my excel file the font is 7.95 (why?). How can I set it to 8? 

     

    Thx,

    Bouyez.

  9. Bouyez
    Bouyez avatar
    14 posts
    Member since:
    Jan 2017

    Posted 08 Feb 2017 Link to this post

    [...]with 1px value (0 hide it ...).  => Not hide, the data is not exported why I define the width with 0px. *
Back to Top