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
20
Error looping through excel rows
posted

I am using Infragistics4.Documents.Excel.v11.2 to create an excel spreadsheet.  I am able to load all of the data correctly.  I then go to format the sheet and set the font.  Using this code:

 

'Sheet is already populated

Dim sheet As Worksheet

For Each row as WorksheetRow in sheet.Rows

    For Each cell as WorksheetCell in row.Cells

        cell.CellFormat.Font.Name = "Trebuchet MS"

    Next

Next

 

As I'm processing the second row, the cell Next statement throws the exception:

Collection was modified after the enumerator was instantiated.

 

Stack Trace:

   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)

   at System.Collections.Generic.SortedList`2.Enumerator.MoveNext()

   at Infragistics.Documents.Excel.WorksheetRow.<GetCellsWithData>d__a.MoveNext()

   at Infragistics.Documents.Excel.WorksheetCellCollection.<GetEnumeratorHelper>d__0.MoveNext()

   at ConsoleApplication1.Module1.Main()

 

Any ideas what is causing this error to be thrown?

 

 

Parents Reply Children