I would like to get the values of a non contiguous, multi area range in excel using C#. I have seen another SO question that says I can do something like this:
obj[,] data = sheet.get_Range("B4:K4,B5:K5").get_Value();
However, when I examine the result I see that I only get the data from the first area: "B4:K4"
.
Testing further, I found that if I request the data in the following way:
obj[,] data = sheet.get_Range( "B4:K4","B5:K5").get_Value();
I get the data for both areas...
So, my question is, is there a way to programmatically combine area addresses such as "B4:K4,B5:K5"
in order to get all of the data to which they refer?
Thanks
If you are trying to get the data from a range table with hidden rows, another technique is to grab the visible cells, and copy them to a new worksheet. When pasted, they will form a contiguous region and the normal object[,] array can be retrieved.
The solution I came up with isn't as elegant as I would have liked but it does the trick nonetheless:
Hope this helps someone else...
Another way would be to combine the non-contiguous areas together into a named range, and just reference that named range within your C# code. Here is a way to do this (assign this formula to a named range in the Excel Name Manager):
The downside with this method is that each area can only be 1 row high.