title: I'm having trouble transferring datagridview to Excel
body: <p>What is the reason I am getting the error like in datagridview below?</p>
  
  <blockquote>
    <p>System.InvalidCastException: The COM object of type '' Microsoft.Office.Interop.Excel.ApplicationClass' could not be assigned to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call in the COM component for the interface with the IID '{000208D5-0000-0000-C000-000000000046}' failed with the following error: Error loading type library / DLL. (HRESULT exception returned: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)). '</p>
  </blockquote>
  
  <p>The code I wrote is:</p>
  
  <pre><code>saveFileDialog.InitialDirectory = "C:";
  saveFileDialog.Title = "Save as Excel File";
  saveFileDialog.FileName = "Data";
  saveFileDialog.Filter = "Excel Files(2003)|*.xls|Excel Files(2007)|*.xlsx";
  
  if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
  {
      Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
      excelApp.Application.Workbooks.Add(Type.Missing);
  
      excelApp.Columns.ColumnWidth = 20;
  
      for (int i = 1; i &lt; dgwReport.Columns.Count + 1; i++)
      {
          excelApp.Cells[1, i] = dgwReport.Columns[i - 1].HeaderText;
      }
  
      for (int i = 0; i &lt; dgwReport.Rows.Count; i++)
      {
          for (int j = 0; j &lt; dgwReport.Columns.Count; j++)
          {
              excelApp.Cells[i + 2, j + 1] = dgwReport.Rows[i].Cells[j].Value;
          }
      }
  
      excelApp.ActiveWorkbook.SaveCopyAs(saveFileDialog.FileName.ToString());
      excelApp.ActiveWorkbook.Saved = true;
      excelApp.Quit();
  }
  </code></pre>