title: Exporting dataset to xlsx with Microsoft.Office.Interop.Excel
body: <p>I was using the following Code in order to export a dataset to xlsx.
  Everything works fine when i am on .net 4.0 but there is a server that requires the framework to be in 3.5 unfortunately and i can't do anything about it. So i changed the framework from 4.0 to 3.5 and when i execute the code i get an error </p>
  
  <blockquote>
    <p>Old format or invalid type library. (Exception from HRESULT:
    0x80028018 (TYPE_E_INVDATAREAD))</p>
  </blockquote>
  
  <p>the error happens when the bellow line executes</p>
  
  <blockquote>
    <p>Excel.Workbook workBook = excel.Workbooks.Add();</p>
  </blockquote>
  
  <p>this is my Code</p>
  
  <pre><code>static void Main(string[] args)
          {
  
               String filepath = "C:/test.csv";            
               DataSet ds = Convert(filepath.ToString(), "tblCustomers", "\t");            
               Excel.Application excel = new Excel.Application();           
               Excel.Workbook workBook = excel.Workbooks.Add();   
               Excel.Worksheet sheet = (Excel.Worksheet)workBook.ActiveSheet;
              int i = 0;            
                  for (int j = 0; j &lt; ds.Tables[0].Columns.Count; j++)
                  {
                      sheet.Cells[i + 1, j + 1] = ds.Tables[0].Columns[j].ToString();            
                  }
  
                  i = 1;                
              foreach (DataRow row in ds.Tables[0].Rows)
              {                              
                  for (int j = 0; j &lt; row.ItemArray.Length; j++)
                  {
                      sheet.Cells[i + 1, j + 1] = row[j].ToString().Trim();
                      //cleangth = row[j].ToString().Trim().Length *10;
  
                  }
  
                  i++;
              }
  
  
              workBook.SaveAs(@System.IO.Directory.GetCurrentDirectory() + "\\test.xlsx");
              workBook.Close();           
  
          }
  </code></pre>
  
  <p>Any suggestions ?</p>