Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
850
Export Merged cells
posted

Hello guys, I'm trying to export my ultragrid with merged cells to excel,

but excel is not respecting the merged cells. How can I solve this?

I tried this using the following code:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Private

 

Sub UltraGridExcelExporter1_CellExported(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.CellExportedEventArgs) Handles UltraGridExcelExporter1.CellExported

Dim cell As UltraGridCell = e.GridRow.Cells(e.GridColumn)

 

 

Dim mergedCell() As UltraGridCell = cell.GetMergedCells()

 

 

If Not mergedCell Is Nothing Then

 

 

Dim isFirstCell As Boolean = True

 

 

For Each mergedCell1 As UltraGridCell In mergedCell

 

 

If cell.Row.Index > mergedCell1.Row.Index Then

isFirstCell =

False

 

 

Return

 

 

End If

 

 

If isFirstCell Then

 

 

Dim rowIndex As Integer = e.CurrentRowIndex

 

 

Dim colIndex As Integer = e.CurrentColumnIndex

e.CurrentWorksheet.MergedCellsRegions.Add(rowIndex, colIndex, rowIndex + (mergedCell.Length - 1), colIndex)

 

 

End If

 

 

Next

 

 

End If

End

Sub

 

Sub

Sub

 

 

But in this line code

e.CurrentWorksheet.MergedCellsRegions.Add(rowIndex, colIndex, rowIndex + (mergedCell.Length - 1), colIndex)

I'm getting this exception and I don´t know why.

"Merged cell regions can't overlap"

The appearance of my ultragrid is shown in the picture.

 

Help me please.

Parents
  • 850
    posted

    Hi Mike,

    Look at the picture, that's the problem that I'm having , I got no colors in excel.

    This is the code that I'm using for now to export my ultragrid to excel.

    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click

     

     

    Me.SaveFileDialog1.Filter = "xls files (*.xls)|*.xls|All files (*.*)|*.*"

     

     

    If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

     

     

    Me.UltraGridExcelExporter1.Export(Me.UltraGrid1, Me.SaveFileDialog1.FileName)

    Process.Start(

    Me.SaveFileDialog1.FileName)

     

     

    End If

    End

    Sub Private Sub UltraGridExcelExporter1_CellExported(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.CellExportedEventArgs) Handles UltraGridExcelExporter1.CellExported

     

     

    Dim cell As UltraGridCell = e.GridRow.Cells(e.GridColumn)

     

     

    Dim mergedCell() As UltraGridCell = cell.GetMergedCells()

     

     

    If Not mergedCell Is Nothing Then

     

     

    Dim isFirstCell As Boolean = True

     

     

    For Each mergedCell1 In mergedCell

     

     

    If cell.Row.Index > mergedCell1.Row.Index Then

    isFirstCell =

    False

     

     

    Return

     

     

    End If

     

     

    Next

     

     

    If isFirstCell Then

    e.CurrentWorksheet.MergedCellsRegions.Add(e.CurrentRowIndex, e.CurrentColumnIndex, e.CurrentRowIndex + (mergedCell.Length - 1), e.CurrentColumnIndex)

     

     

    End If

     

     

    End If

    End Sub

     

    Note: by the way, I'm using excel 2003, I don't know if that could be a reason of this behavior.

     

    Any suggestion or solution?

    I was wondering too if you can attach a example of this that work properly.

     

    Regards

     

Reply Children
No Data