This project has moved. For the latest updates, please go here.

Read range of data

Sep 24, 2012 at 2:24 PM

Is there possibility to read range of data?

With Microsoft.Office.Interop.Excel I could use


string upLeft = "A1";

string downRight = "C10";

object[,] array = (object[,])excelWorksheet.get_Range(upLeft, downRight).Value;

Sep 24, 2012 at 3:21 PM

You can do a projection:

var contents = ws.Range("A1:C10").Rows().ToDictionary(r => r.RowNumber(), r => r.Cells().Select(c => c.Value).ToList());

This will give you a Dictionary<int, List<Object>>

Why would you need to do this?

Sep 25, 2012 at 2:29 PM

I used Microsoft.Office.Interop.Excel, but there are lot of problems with it. I just want to rewrite some methods, so it will use ClosedXML, not Excel Interop.

I read cells iteralively to fill an array and It seem to be fast enough for me.


But I found another problem. It is getting value of formula.

Methods I use are generics, so user defines return type. While there is no formula, everything is all right, but when there is formula ValueCached returns string and I cannot parse unknown type. Why is ValueCached string, not an object? Is there any way to bypass this problem?


Thank you.