Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The right way to lookup a value from within a table and fill it with data

My current project is basically the conversion of an excel spreadsheet to a windows application. I came across a section of the worksheet using a table and vlookups. Assume the table looks like this (exactly like this only each quarter with an additional row added to the bottom):

enter image description here

I want to imitate the vlookups in C# and I can think of several different ways, however I am looking for what the "best" way is. By "best", I mean easiest to code and most maintainable, I don't mean speed, if it works in under 10 seconds its good enough. this is happening in a method that has the region name and Yr/Qrt passed in as strings. Using those, what data structures should I use to store the table data in and how can I do it in the least amount of code?

EDIT

I have now recieved the actual excel file that I will be extracting this data from. Any advice on how to get only the "yearQtr" fields and the HRTC fields with C# would be greatly appreciated

Edit

just discovered that them machine running this application will not have excel. So the file shown above will have to be changed into another format before it is read in to the application(this will be handled by manually saving the file from excel as csv or xml or whatever format. So I guess my question is how to get the above described data out of a csv or xml

like image 437
jth41 Avatar asked Mar 26 '13 13:03

jth41


People also ask

Which function is best to lookup and retrieve data from a specific row in a table?

Use VLOOKUP to search one row or column, or to search multiple rows and columns (like a table).

How do you look up a value and return the cell to the right?

If you want to look up for a value and return below and the 3 cells to the right of the reference, you can apply this formula =INDEX(F1:H8,MATCH(K1,F1:F8,0)+1,3).


1 Answers

You may do it this way:

public class MyClass
{
    public List<string> columns;
}

Then in the form, you can do the look up like this:

List<MyClass> myValues;

public List<MyClass> LookUp(string value, int columnIndex)
{
    return this.myValues.Where(
                     input => input.columns[columnIndex] == value
                              ).ToList();     
}
like image 162
Hossein Narimani Rad Avatar answered Sep 18 '22 17:09

Hossein Narimani Rad