title: export data in a list and array to excel using c#
body: <p>I have a list of numbers in one class. I am trying to export the data in the list and the data in array[4,4] to Excel. I would like the list as one column with the header and the array as a table with headers (column name) and row names.</p>
  
  <p>I did not find a proper solution to try</p>
  
  <pre><code>   public void Data_to_Excel()
      {
  
          //start excel
          NsExcel.Application excapp = new Microsoft.Office.Interop.Excel.Application();
  
          //if you want to make excel visible           
          excapp.Visible = true;
  
          //create a blank workbook
          var workbook = excapp.Workbooks.Add(NsExcel.XlWBATemplate.xlWBATWorksheet);
  
          //or open one - this is no pleasant, but yue're probably interested in the first parameter
          string workbookPath = " filepath here ";
          workbook = excapp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
  
  
          //Not done yet. You have to work on a specific sheet - note the cast
          //You may not have any sheets at all. Then you have to add one with NsExcel.Worksheet.Add()
          var sheet = (NsExcel.Worksheet)workbook.Sheets[1]; //indexing starts from 1
  
          //do something usefull: you select now an individual cell
          //var range = sheet.get_Range("A1", "A1");
          //range.Value2 = "test"; //Value2 is not a typo
  
          //now the list
          string cellName;
          int counter = 1;
          foreach (var item in Sim_Obj.Bottom_Rows_Count_Stack)
          {
              cellName = "A" + counter.ToString();
              var range = sheet.get_Range(cellName, cellName);
              range.Value2 = item.ToString();
              ++counter;
          }
  
          workbook.SaveAs("Cash_Surge_Sim_Results.xlsx");
  
  
      }
  </code></pre>
  
  <p>I have the 20 results in the rich text box in a list.
  I have table layout data in an array[4,4]</p>
  
  <p>I want the array data as a table form in Excel and 
  the list data as one column.</p>