I am trying to read data from an Excel document in C # using Microsoft COM Interop.
So far I can download the document and read some data from it. However, I need to read data from two different columns and output them as json (to call jQuery ajax)
I made a quick prototype of how my Excel document is structured with the hope that it is a little easier to explain; -)

The method I have is called GetExcelDataByCategory(string categoryName)
, where the categoryName parameter will be used to find in which column to receive the data.
So, if I make a call with the “Category 2” parameter as a parameter, I need to get all the values in the columns of row C and the corresponding dates from column A, so the output will look like this:

Which then needs to be converted / processed to JSON.
I searched high and low how to achieve this, but so far no luck :-( I know that I can use the get_Range () method to select a range, but it seems you need to explicitly specify the method from which the row and which column will receive data. Ie: get_Range ("A1, C1")
This is my first experience reading data from an Excel document, so I guess there is a lot to learn ;-) Is there a way to get output in my second image?
Any help / hint is much appreciated !:-)
Thanks in advance.
All the best
Bo
source share