Reading from Excel (Range into multidimensional Array) C#

calendar_today Asked May 26, 2009
thumb_up 13 upvotes
history Updated April 16, 2026

Question posted 2009 · +10 upvotes

How would I read from an Excel sheet and load the marked selection (Area) into an multidimensional array? A column in Excel could itself be a multi dimensional array since it would contain more than just one value.

The idea (not sure how good or bad this is) is right now is to do a for loop through all the Excel.Area (selected fields) and add the content of that field to the multi dimensional array. Since the multi dimensional array is of type object[,] and therefore non-generic there is no convenient add() method to it. All of it needs to be done manually.

Any idea if this approach is ok or if it could be done more efficientlty?

Many Thanks,

Accepted answer +13 upvotes

You can read the value of Range as array:

using (MSExcel.Application app = MSExcel.Application.CreateApplication()) 
{
    MSExcel.Workbook book1 = app.Workbooks.Open( this.txtOpen_FilePath.Text);
    MSExcel.Worksheet sheet = (MSExcel.Worksheet)book1.Worksheets[1];
    MSExcel.Range range = sheet.GetRange("A1", "F13");

    object value = range.Value; //the value is boxed two-dimensional array
}

This code snippet is from .NET wrapper for MS Office. But same princip is in VSTO or VBA in MS Excel.

Excel VBA objects referenced (5)

Top excel Q&A (6)

+13 upvotes ranks this answer #54 out of 167 excel solutions on this site .