title: How to add excel column to worksheet
body: <p>Does any one know how to insert a new column to an already existing work sheet. </p>
  
  <p>My current solution right now is to create a new excel file by copying all the columns from the existing excel then add the new col in the data table then exporting it to create a new excel. This method is somewhat tedious and just adding the new column to the already existing excel is the best way I see.</p>
  
  <p>Here is my function for creating a new excel file</p>
  
  <pre><code>public static void ExportToExcel(DataTable tbl)
      {
          try
          {
              string dateNow = String.Format("{0:MM_dd_yyyy HH_mm_ss}", DateTime.Now);
              string excelFilePath = "C:\\The_Excel_File\\Result_" + dateNow;
  
  
              if (tbl == null || tbl.Columns.Count == 0)
                  throw new Exception("ExportToExcel: Null or empty input table!\n");
  
              // load excel, and create a new workbook
              var excelApp = new Microsoft.Office.Interop.Excel.Application();
              excelApp.Workbooks.Add();
  
              // single worksheet
              Microsoft.Office.Interop.Excel._Worksheet workSheet = excelApp.ActiveSheet;
  
              // column headings
              for (var i = 0; i &lt; tbl.Columns.Count; i++)
              {
                  workSheet.Cells[1, i + 1] = tbl.Columns[i].ColumnName;
              }
  
              // rows
              for (var i = 0; i &lt; tbl.Rows.Count; i++)
              {
                  // to do: format datetime values before printing
                  for (var j = 0; j &lt; tbl.Columns.Count; j++)
                  {
                      workSheet.Cells[i + 2, j + 1] = tbl.Rows[i][j];
                  }
              }
  
              // check file path
              if (!string.IsNullOrEmpty(excelFilePath))
              {
                  try
                  {
                      workSheet.SaveAs(excelFilePath);
                      excelApp.Quit();
                      //MessageBox.Show("Excel file saved!");
                  }
                  catch (Exception ex)
                  {
                      throw new Exception("ExportToExcel: Excel file could not be saved! Check filepath.\n"
                                          + ex.Message);
                  }
              }
              else
              { // no file path is given
                  excelApp.Visible = true;
              }
          }
          catch (Exception ex)
          {
              throw new Exception("ExportToExcel: \n" + ex.Message);
          }
      }
  </code></pre>