title: How can I fill a datatable from an excel listobject table
body: <p>My main problem is getting the information from my list object in the excel spreadsheet. For some reason it wont convert the string to int see where I have commented. Any help would be greatly appreciated.</p>
  
  <pre><code>public static DataTable excelDerivedAssembliesDT(string excelDir, int jobID)
  {
  
   DataTable dt = new DataTable();
   var excelApp = new Excel.Application();
  
   try
   {
   excelApp.Visible = false;
   excelApp.Workbooks.Open(excelDir);
   Excel.ListObject vstoListObject = excelApp.Worksheets[1].ListObjects[1];
  
  　DataColumn assemblyID = new DataColumn();
   assemblyID.DataType = System.Type.GetType("System.Int32");
   assemblyID.ColumnName = "assemblyID";
   assemblyID.AutoIncrement = true;
  dt.Columns.Add(assemblyID);
  
  DataColumn assemblyNo = new DataColumn();
   assemblyNo.DataType = System.Type.GetType("System.Int32");
   assemblyNo.ColumnName = "assemblyNo";
  dt.Columns.Add(assemblyNo);
  
   DataColumn job = new DataColumn();
   job.DataType = System.Type.GetType("System.Int32");
   job.ColumnName = "jobID";
  dt.Columns.Add(job);
  
   DataColumn assemQTY = new DataColumn();
   assemQTY.DataType = System.Type.GetType("System.Int32");
   assemQTY.ColumnName = "assemblyQty";
  dt.Columns.Add(assemQTY);
   DataRow dataRow = dt.NewRow();
  　
  　　
   foreach (Excel.ListRow row in vstoListObject.ListRows)
  {
  　//This is the part i cant seem to get to work i just cant see why it shouldn't
  　
   dataRow["assemblyNo"] = (int)(row.Range.Cells[1, 1]).ToString());
  
   dataRow["assemblyQty"] = (int)(row.Range.Cells[1, 2]).ToString());
  
   dataRow["jobID"] = (int)(row.Range.Cells[1, 3]).ToString());
  
  dt.Rows.Add(dataRow);
  dataRow = dt.NewRow();
  
  
  }
  
  dt.AcceptChanges();
  
  }
  
   catch(exception e)
   {
       MessageBox.Show(e.ToString());
  
   }
   return dt;
  
  }
  　
  　
  </code></pre>
  
  <p>Thanks in advance.</p>