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

Grouped Grid - Export Excel - Remove Extra Column

2 Answers 237 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 01 Jun 2009, 11:21 PM
Hi there,
Spent quite a while looking into this and haven't seen an answer yet...

I have a "simple" grouped grid. When I export it to Excel, there is an extra empty column (A). How can I remove this first column from excel.

Here is what I've tried...
I assume the empty column is a combination of GridGroupSplitterColumn and Header Column. Using the following code...

Protected Sub btnExport_Click(ByVal sender As ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles btnExport.Click  
        RadGrid1.ExportSettings.ExportOnlyData = True 
        RadGrid1.ExportSettings.IgnorePaging = True 
        RadGrid1.ExportSettings.OpenInNewWindow = True 
        RadGrid1.MasterTableView.ExportToExcel()  
End Sub 
 
Protected Sub RadGrid1_ExcelExportCellFormatting(ByVal source As ObjectByVal e As Telerik.Web.UI.ExcelExportCellFormattingEventArgs)  
        If TypeOf e.FormattedColumn Is GridGroupSplitterColumn Then 
            e.Cell.Visible = False 
        End If 
End Sub 

...I am able to remove many of the blank cells. But the header row and grouped rows still have an empty cell on the left. So again, my question is, how can I remove all empty cells in that first column (A) when exporting a grouped grid to Excel?

Thanks for your help...
Joe

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Jun 2009, 06:30 AM
Hello Joe,

You can try out the following code to remove the empty cells in the Header row and GroupHeader rows while exporting:
c#:
   Protected Sub btnExport_Click(ByVal sender As ObjectByVal e As EventArgs) 
       TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem).Cells(0).Visible = False 
       For Each gpheaderItem As GridGroupHeaderItem In RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader) 
               
           gpheaderItem.Cells(0).Visible = False 
       Next 
        
       RadGrid1.ExportSettings.IgnorePaging = True 
       RadGrid1.ExportSettings.ExportOnlyData = True 
       RadGrid1.ExportSettings.OpenInNewWindow = True 
       RadGrid1.MasterTableView.ExportToExcel() 
   End Sub 
 
 

Thanks
Princy.
0
Joe
Top achievements
Rank 2
answered on 02 Jun 2009, 01:51 PM

Princy,
Your code did not do the trick in the btn_Export Sub, but I moved it to the ExcelExportCellFormatting Sub and it worked great.
Thanks for your help!

Here is the new code that gets rid of the first "empty" column for a grouped grid export...


Protected
 Sub btnExport_Click(ByVal sender As ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles btnExport.Click  
        RadGrid1.ExportSettings.ExportOnlyData = True 
        RadGrid1.ExportSettings.IgnorePaging = True 
        RadGrid1.ExportSettings.OpenInNewWindow = True 
        RadGrid1.MasterTableView.ExportToExcel()  
End Sub 
 
Protected Sub RadGrid1_ExcelExportCellFormatting(ByVal source As ObjectByVal e As Telerik.Web.UI.ExcelExportCellFormattingEventArgs)  
        TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem).Cells(0).Visible = False 
        For Each gpheaderItem As GridGroupHeaderItem In RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)  
            gpheaderItem.Cells(0).Visible = False 
        Next 
        If TypeOf e.FormattedColumn Is GridGroupSplitterColumn Then 
            e.Cell.Visible = False 
        End If 
        ' This will resize the column in Excel  
        If e.FormattedColumn.UniqueName = "myUniqueColumnName" Then 
            e.Cell.Width = Unit.Pixel(200)  
        End If 
    End Sub 
 
Tags
Grid
Asked by
Joe
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Joe
Top achievements
Rank 2
Share this question
or