title: how to set values to a two-dimensional Excel range?
body: <p>I need to build an excel sheet from a list of test-cases in a specific format in order to upload it it to the server.
  I've trubles to populate the two dimensional range of "expected" and "actual" in the file.
  I use the same methods in order to populate the headers, which is a one-dimensional array, and the steps (which is two-dims).</p>
  
  <p>The flow is:</p>
  
  <ol>
  <li>Defunding the TestCase range (some headers + steps). Let's say: A1 to E14 for the 1st iteration.</li>
  <li>Depunding a sub (local) range within the testCase range for the headers (e.g: A1 to C1).</li>
  <li>Depunding another sub (local) range within the testCase range for the headers (in my case: D1 to E14).</li>
  <li>Populate the two sub-ranges with a test-case values (headers and steps).</li>
  <li>Repeat by defunding the next spreadsheet range (A14 to E28 in my case) with same local ranges (steps 2-3), and populate them, and so on...</li>
  </ol>
  
  <p>The source value is a Dictionary which represents the test-case's steps (key = expected and value = actual).</p>
  
  <p>Here is the code I use:</p>
  
  <pre><code>public class TestCase
  {
      public Dictionary&lt;string, string&gt; steps;
  }
  
  Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
  Workbooks workBooks = excelApp.Workbooks;
  Workbook workbook = workBooks.Add(XlWBATemplate.xlWBATWorksheet);
  Worksheet worksheet = (Worksheet)workbook.Worksheets[1];
  excelApp.Visible = true;
  
  foreach (TestCase testCase in TestCaseList.Items.GetList())
  {
      Range worksheetRange = GetRangeForTestCase(worksheet);
      //The step above is equivalent to:
      //    Range worksheetRange = worksheet.get_Range("A1", "E14");
      //for the first foreach iteration.
  
      Range stepsRange = worksheetRange.get_Range("D1", "E14");
      //This is a local range within the worksheetRange, not the worksheet,
      //so it is always have to be between D1 to E14 for a 14th steps test case.
      //Anyway, it should work at least for the 1st iteration.
  
      //for test evaluation only. All cells between D1 to E14 are filled with "ccc"
      test.Value = "ccc";
  
      //This list of pairs which are converted to Array[,] is about to be converted to a two dimensional array
      list = new List&lt;object&gt;();
      foreach (KeyValuePair&lt;string, string&gt; item in testCase.Steps)
      {
          //Here I build the inside Array[,]
          object[] tempArgs = {item.Key, item.Value};
          list.Add(tempArgs);
      }
      object[] args = { Type.Missing, list.ToArray() };
  
      test.GetType().InvokeMember("Value", System.Reflection.BindingFlags.SetProperty, null, test, args);
  
      //Now, all the "ccc" within the Excel worksheet are disapeared, so the Range is correct, but the value of args[] are not set!!
  }
  </code></pre>
  
  <p>The actual results of running this code is that the range is defined (probably correctly) but its values are set to null,
  although - I can see the correct values in the args array in run time.
  I've also tried to set a wider range and populate it with range.Value = "Pake value" and saw that, after running my peace of code, the correct range of steps become blank!
  So, the range is correct, the array is filled with my values, the InvokeMember method is correctly invoked :)
  But, all values are set to null..</p>
  
  <p>Help...</p>