Search code examples
c#epplus

C#: How to access values from Object[ , ]


I am using EPPlus for reading excel file and I got all excel rows and columns where data is present as Object[,]

enter image description here

I tried to access individual values using data[0,0] but it fails.

How can I access the individual values in this Object[,] ?


Solution

  • You can access it like

    var data = worksheet.Cells[0,0].Value;
    

    So you need to define the index at cell level, not at value level.

    Since ExcelWorksheet.Cells.Value is of type object, you first need to cast to object[,] if you are trying to access on value level:

    var data = ((object[,])worksheet.Cells.Value)[0,0];