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

Radgrid export to excel, hide column in excel

8 Answers 2161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bouyez
Top achievements
Rank 1
Bouyez asked on 16 Jan 2017, 04:12 PM

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.

8 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 16 Jan 2017, 05:04 PM

Hello ,

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.
0
Bouyez
Top achievements
Rank 1
answered on 18 Jan 2017, 11:08 AM

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.

0
Rumen
Telerik team
answered on 20 Jan 2017, 04:22 PM

Hello Jordan,

If you set  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 the grid should be  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.
0
Bouyez
Top achievements
Rank 1
answered on 24 Jan 2017, 10:00 AM

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?

 

0
Bouyez
Top achievements
Rank 1
answered on 27 Jan 2017, 11:33 AM

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 

0
Rumen
Telerik team
answered on 31 Jan 2017, 04:00 PM

Hello ,

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.
0
Bouyez
Top achievements
Rank 1
answered on 08 Feb 2017, 11:04 AM

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.

0
Bouyez
Top achievements
Rank 1
answered on 08 Feb 2017, 11:07 AM
[...]with 1px value (0 hide it ...).  => Not hide, the data is not exported why I define the width with 0px. *
Tags
Grid
Asked by
Bouyez
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Bouyez
Top achievements
Rank 1
Share this question
or