How to create dictionary for data from Excel sheet to display in Console application (c#)
<p>The idea of the project I'm implementing is to get some data from an excel sheet as seen below:
<a href="http://i.stack.imgur.com/fKKep.png" rel="nofollow">column : FileName/docName and row:cells B-J (fieldType) are two things used to create a key </a>
The docName and Fieldtype are concatenated in the format (docName/fieldType) to give me a key which I store in a dictionary.
I need to store the value from the corresponding cell from the excel sheet that matches to the key with the condition that its not null.</p>

<pre><code>public class ReadingExcel
{
    #region Members

    int col = 1;
    int row = 1;
    int limit = 0;
    int valLimit = 1;
    int colLimit = 0;
    int rowLimit = 0;
    int totalColumns;
    int totalRows;
    string resultRowTemp = string.Empty;
    string result = string.Empty;
    StringBuilder concatValue = new StringBuilder();
    Application excelApp = new Application();
    Workbook ExtractionBook;
    Worksheet Sheet;
    Range dataRange;
    List&lt;string&gt; docName = new List&lt;string&gt;();
    List&lt;string&gt; fieldType = new List&lt;string&gt;();
    List&lt;string&gt; rowFieldValues = new List&lt;String&gt;();
    List&lt;string&gt; excelData = new List&lt;String&gt;();
    List&lt;string&gt; concatKey = new List&lt;string&gt;();
    Dictionary&lt;string,List&lt;string&gt;&gt; docFieldDictionary = new Dictionary&lt;string,List&lt;string&gt;&gt;();
    #endregion

    #region Public Methods

    public void ExtractKeys(string docPath, string sheetName, string key)
    {

        ExtractionBook = excelApp.Workbooks.Open(docPath);
        Sheet = (Worksheet)ExtractionBook.Sheets[sheetName];
        dataRange = (Range)Sheet.Cells;
        totalColumns = Sheet.UsedRange.Columns.Count;
        totalRows = Sheet.UsedRange.Rows.Count;

        //To get the docName alone 
        for (row = 2; row &lt;= totalRows; row++)
        {
            dataRange = (Range)Sheet.Cells[row, col];
            result = (string)dataRange.Value2;
            if (!string.IsNullOrEmpty(result))
            {
                docName.Add(result);

            }
        }

        //To get the fields alone     
        for (col = 1; col &lt;= totalColumns; col++)
        {
            dataRange = (Range)Sheet.Cells[col];
            result = (string)dataRange.Value2;
            if (!string.IsNullOrEmpty(result))
            {
                fieldType.Add(result);
            }
        }

        //To create the Dictionary Keys
        for (limit = 0; limit &lt; docName.Count; limit++)
        {
            for (valLimit = 1; valLimit &lt; fieldType.Count; valLimit++)
            {

                concatValue = concatValue.Append(docName[limit]).Append("/").Append(fieldType[valLimit]);
                result = concatValue.ToString();
                concatKey.Add(result);
                concatValue.Clear();

            }

        }
</code></pre>

<p>I am clueless on how to proceed further to add the key and how to obtain the corresponding value from the excel sheet.</p>

<p>The next step I tried is to store all the fieldType values for a corresponding docName in rowFieldValues list.</p>

<pre><code>      //To read the entire excel sheet
            for (row = 2; row &lt;= totalRows; row++)
            {
                for (col = 1; col &lt;= totalColumns; col++)
                {
                    dataRange = (Range)Sheet.Cells[row, col];
                    result = (string)dataRange.Value2;
                    excelData.Add(result);               
                }
            }
            // To fetch and store data for each docName
            for ( rowLimit = 0; rowLimit &lt; excelData.Count; rowLimit++)
            {
                for (limit = 0; limit &lt; docName.Count; limit++)
                {
                    if (docName[limit] == excelData[rowLimit])
                    {
                        for (colLimit = 0; colLimit &lt; fieldType.Count; colLimit++)
                        {
                            rowFieldValues.Add(excelData[colLimit]);
                            docFieldDictionary.Add(docName[limit], rowFieldValues);
                        }
                    }
                }       
            }
</code></pre>

<p>I've got three problems:</p>

<p>1.rowFieldValues list returns the same data for all the docNames.</p>

<p>2.I get the error <a href="http://i.stack.imgur.com/IzKTf.png" rel="nofollow">error msg saying: same dicitonary key is already added</a></p>

<p>3.I am not able to iterate to the next docName in the nested for loops once all the rowFieldValues for one docName is added to the list.</p>