Add Excel Range to Lists without looping in C#

Last Reply on Jul 12, 2016 08:56 AM By Aporvi

Posted on Jul 12, 2016 05:52 AM
xlRangeDB = xlWorkSheetDB.get_Range("A2", "BA" + lRow.ToString());
                object[,] valueArray = xlRangeDB.Value2;

                List<string> inputData = new List<string>();
I would like to convert a Excel Range (xlRangeDB) to List. I couldn't find a direct way so I first convert excel range to Array and then try to add into List. But it doesn't work either.
You are viewing reply posted by: Aporvi on Jul 12, 2016 08:56 AM.
Posted on Jul 12, 2016 08:56 AM

Hi Dharmendr,

I have (.xlsb) excel files therefore OLEDB does not work properly.

OpenXml go through each rows. Which is not optimal if you have 200 workbooks and each workbook contains 70,000 rows and 70 columns of data.

However I found a way:

var inputData = valueArray.Cast<object>().Select(Convert.ToString).ToList();