GetEnumerator throws System.IndexOutOfRangeException

Hi. When we use GetEnumerator method, we get “Current = ‘Current’ threw an exception of type ‘System.IndexOutOfRangeException’” error. We are using C#.

file.Worksheets[0].Cells.Rows[0].GetEnumerator();

@ocelllotatata,

Could you please share your sample Excel file and complete sample code. We will check your issue soon.

This sample code:

workbook = new Workbook(file.OpenReadStream());
Cells cells = workbook.Worksheets[0].Cells;
IEnumerator header1 = cells.Rows[0].GetEnumerator();
IEnumerator row1 = cells.Rows[1].GetEnumerator();

Actually, excel file had one column. Example Row 0 - Name, Row 1 - Aspose etc.

@ocelllotatata

I tested your scenario/case using the following sample code with the attached Excel file and it works fine:
e.g.
Sample code:

            Workbook workbook = new Workbook(File.OpenRead("g:\\test2\\Bk_testenum1.xlsx"));
            Cells cells = workbook.Worksheets[0].Cells;
            Cell currentCell = null;
            IEnumerator header1 = cells.Rows[0].GetEnumerator();         
            // Traverse cells in the collection in the first row.
            while (header1.MoveNext())
            {
                currentCell = header1.Current as Aspose.Cells.Cell;
                Console.WriteLine(currentCell.Value);

            }
            
            IEnumerator row1 = cells.Rows[1].GetEnumerator();
            // Traverse cells in the collection in the second row.
            while (row1.MoveNext())
            {
                currentCell = row1.Current as Aspose.Cells.Cell;
                Console.WriteLine(currentCell.Value);
            }

Bk_testenum1.zip (6.2 KB)

Thank you for your attention. I am getting the same error when I use your sample code and excel file. Could it be a problem with the version difference? I am using 22.7.0v.

@ocelllotatata,

Could you please try using our latest version/fix, Aspose.Cells for .NET 23.4 with my sample Excel file and sample code. Let us know if you still find any issue with latest version.

I am sorry but I can’t try latest version. Because, my license supports up to August 2022 for upgrade.

@ocelllotatata,

We are sorry but we cannot evaluate issues based on older APIs. We cannot include fixes to older APIs. The fixes are based on latest APIs set only.

1 Like