简体   繁体   中英

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[,]

在此处输入图像描述

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

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

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM