Reading from Excel (Range into multidimensional Array) C#
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.
Here is the C# code to do this with SpreadsheetGear:
// Load the workbook.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(@"MyWorkbook.xlsx");
// Get a range of cells as an array of object[,].
object[,] values = (object[,])workbook.Worksheets["MySheet"].Cells["A1:J10"].Value;
SpreadsheetGear also provides fast APIs for accessing cells one at a time so that you can avoid copying the values to an array without sacrificing performance.
Disclaimer: I own SpreadsheetGear LLC