title: How to speed up writing to an Excel sheet
body: <p>I am currently using Interop objects to write to an Excel spreadsheet. Using stopwatches, I have found that the following implementation is quite timely. The processes in the <code>foreach</code> loop will usually take around 50 seconds to write around 2000 rows, each with 9 columns.</p>
  
  <p>Is there any way to speed this up?</p>
  
  <pre><code>List&lt;string[]&gt; allEntries = fillStringArrayList();
  
  // Set-up for running Excel
  xls = new Excel.Application();
  workBooks = xls.Workbooks;
  workBook = workBooks.Open(workbookPath);
  var workSheet = workBook.Sheets["Sheet1"];
  
  // Insert new entries
  foreach (string[] entry in allEntries)
  {
      // Get the final row in the sheet that is being used
      Excel.Range usedRange = workSheet.UsedRange;
      int rowCount = usedRange.Rows.Count;
  
      // Format Column A to be type "text"
      workSheet.Cells[rowCount + 1, 1].NumberFormat = "@";
  
      workSheet.Cells[rowCount + 1, 1] = entry[0];
      workSheet.Cells[rowCount + 1, 2] = entry[1];
      workSheet.Cells[rowCount + 1, 3] = entry[2];
      workSheet.Cells[rowCount + 1, 4] = entry[3];
      workSheet.Cells[rowCount + 1, 5] = entry[4];
      workSheet.Cells[rowCount + 1, 6] = entry[5];
      workSheet.Cells[rowCount + 1, 7] = entry[6];
      workSheet.Cells[rowCount + 1, 8] = entry[7];
      workSheet.Cells[rowCount + 1, 9] = entry[8];
  }
  </code></pre>