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

Hide Columns If Group Is Hidden When Exporting To Excel

3 Answers 224 Views
GridView
This is a migrated thread and some comments may be shown as answers.
IT
Top achievements
Rank 1
IT asked on 26 Feb 2016, 10:59 AM

I have a RadGridView which I've used the property builder to add several groups to.When I hide the group, it hides the columns within the group on screen, however when I export the grid to excel, the columns within the group are still visible.

Is there anyway of fixing this so that if the group is hidden, the columns within the group are not exported?

I already have:

        Dim exporter As ExportToExcelML = New ExportToExcelML(Me.grid)
        exporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport
        exporter.SheetName = "Export"
        exporter.SummariesExportOption = SummariesOption.DoNotExport
        Dim filename As String = "C:\Export.xls"
        exporter.RunExport(filename)

Thanks in advance for any help.

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 26 Feb 2016, 11:32 AM
Hello Shane,

Thank you for writing.

The following article shows how you can export a particular group only: Export Data in a Group to Excel.

In addition, you may try our new spread export functionality: Spread export.

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
IT
Top achievements
Rank 1
answered on 26 Feb 2016, 11:57 AM

Hi,

 

These both appear to be about grouping rows? I have Columns grouped using the "Property Builder" tool on the radgridview. For example, I have:

GROUP 1 - Columns 1, 2, 3

GROUP 2 - Columns 4, 5, 6, 7

GROUP 3 - Columns 8, 9, 10

If I hide group 2, the export still exports columns 4, 5, 6 and 7. If I hide the cells through (not the group), they do not export.

I've tried this before the export:

 If Me.grid.Columns("GROUP1").IsVisible = False Then
            Me.grid.Columns("Column4").IsVisible = False
            Me.grid.Columns("Column5").IsVisible = False
            Me.grid.Columns("Column6").IsVisible = False
            Me.grid.Columns("Column7").IsVisible = False

end if

However it throws an error of "NullReferenceException was unhandled. Object reference not set to an instance of an object". I think this may be as GROUP1 isn't a column and therefore I can't check if it is visible or not. 

So basically, I need to know how to check if a group of columns is visible or not?

Thanks, Shane

 

0
Dimitar
Telerik team
answered on 26 Feb 2016, 12:45 PM
Hi Shane,

Thank you for writing back.

You are using ColumnGroupsViewDefinition and in this case, you can check if particular group is visible like this:
Dim view = TryCast(radGridView1.ViewDefinition, ColumnGroupsViewDefinition)
 
If Not view.ColumnGroups(1).IsVisible Then
    radGridView1.Columns(4).IsVisible = False
    radGridView1.Columns(5).IsVisible = False
End If

Let me know if I can assist you further.
 
Regards,
Dimitar
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
IT
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
IT
Top achievements
Rank 1
Share this question
or