Completed
Last Updated: 12 Oct 2015 10:25 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 08 Oct 2015 08:30
Category: GridView
Type: Bug Report
1
FIX. RadGridView - incorrect header layout of the exported Excel file when using ColumnGroupsViewDefinition
To reproduce: 

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    Me.CustomersTableAdapter.Fill(Me.NwindDataSet.Customers)
    Me.RadGridView1.DataSource = Me.CustomersBindingSource
    Dim view As New ColumnGroupsViewDefinition()
    view.ColumnGroups.Add(New GridViewColumnGroup("Customer Contact"))
    view.ColumnGroups.Add(New GridViewColumnGroup("Details"))
    view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Address"))
    view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Contact"))
    view.ColumnGroups(0).Rows.Add(New GridViewColumnGroupRow())
    view.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("CompanyName"))
    view.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("ContactName"))
    view.ColumnGroups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("ContactTitle"))

    view.ColumnGroups(1).Groups(0).Rows.Add(New GridViewColumnGroupRow())
    view.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("Address"))
    view.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("City"))
    view.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("Country"))

    view.ColumnGroups(1).Groups(1).Rows.Add(New GridViewColumnGroupRow())
    view.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns("Phone"))
    view.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns("Fax"))
    RadGridView1.ViewDefinition = view

    RadGridView1.BestFitColumns(BestFitColumnMode.AllCells)
End Sub

Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
    Dim spreadExporter As New GridViewSpreadExport(RadGridView1)
    Dim fileName As String = "..\..\exported.xlsx"
    Dim exportRenderer As New SpreadExportRenderer()
    spreadExporter.SheetName = "Sheet1"
    spreadExporter.ExportVisualSettings = True
    spreadExporter.SummariesExportOption = SummariesOption.ExportOnlyTop
    spreadExporter.SheetMaxRows = ExcelMaxRows._1048576
    spreadExporter.HiddenColumnOption = HiddenOption.DoNotExport    
    spreadExporter.HiddenRowOption = HiddenOption.DoNotExport
    spreadExporter.FileExportMode = FileExportMode.CreateOrOverrideFile
    spreadExporter.RunExport(fileName, exportRenderer)
    Process.Start(fileName)
End Sub

Workaround: by using the SpreadExportRenderer.WorkbookCreated event you can remove the header cells and add new ones in order to display the same header layout as in the grid:
http://www.telerik.com/help/winforms/gridview-exporting-data-spread-export.html
http://www.telerik.com/help/winforms/spreadprocessing-working-with-cells-insert-remove-cells.html
http://www.telerik.com/blogs/getting-started-with-radspreadprocessing-volume-1
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments