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

Merging Cells throws KeyNotFoundException

2 Answers 68 Views
SpreadProcessing
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 27 Mar 2017, 10:36 PM

When I am trying to merge cells in a spreadsheet I get the error "The given key was not present in the dictionary.", I am able to merge cells accross columns on the same row using MergeAccross but I am unable to merge cells in the same column over multiple rows. I am not sure if this is a bug or if it just something I am doing. Any help would be appreciated.

For d As Integer = 0 To arrDate.GetUpperBound(0)
                               fromCellIndex = New CellIndex(5, d + 1)
                               toCellIndex = New CellIndex(10, d + 1)
                               xlWorkSheet.Cells(fromCellIndex, toCellIndex).Clear(ClearType.All)
                               nCellSelection = xlWorkSheet.Cells(fromCellIndex, toCellIndex)
                               nCellSelection.Merge()  <-- Line the error gets thrown.

next d

 

2 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 29 Mar 2017, 05:29 PM

I have found that when I use the SetBorders function that is when I get the KeyNotFoundException. It works fine if you are using .MergeAcross() but throws the error when you are using .Merge()

As soon as I commented out all the "SetBorders" all the cells were able to be merged as expected.

This is how I am using "SetBorders"

Dim nNoBorder As New CellBorder(CellBorderStyle.None, New ThemableColor(Color.Transparent.ToArgb))
Dim nBorder As New CellBorder(CellBorderStyle.Thin, New ThemableColor(Color.Black.ToArgb))

xlWorkSheet.Cells(fromCellIndex, toCellIndex).SetBorders(New CellBorders(nNoBorder, nNoBorder, nNoBorder, nNoBorder, nNoBorder, nNoBorder, nNoBorder, nNoBorder))

0
Tanya
Telerik team
answered on 30 Mar 2017, 01:30 PM
Hi Brian,

I tested the code you provided with a sample data but couldn't reproduce the exception. Could you please share more details on the scenario? Is the error observable in an empty worksheet, which has only the borders applied? Can you share some runnable code, which we can test locally?

If you would like, you can also open a support ticket using your telerik.com account. In the ticketing system, you can attach archives, so you can share a sample project. This way we will be able to reproduce the behavior you are observing and check what might be causing it faster.

Regards,
Tanya
Telerik by Progress

Tags
SpreadProcessing
Asked by
Brian
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or