title: Import data from excel without using OLEDB
body: <p>Hi all is it possible to load excel data without using <code>OLEDB</code>, I have written a code using the connection string as follows for <code>.xls and .xlsx</code></p>
  
  <p><code>ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pFilePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";</code></p>
  
  <p><code>ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pFilePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";</code></p>
  
  <p>In my system as <code>12.0</code> related <code>dll</code> is not present I got an error. So I would like to know whether there is any way to achieve my requirement rather than the general approach</p>
  
  <p>Sample Code written</p>
  
  <pre><code>public void Method(string pFilePath)
      {
          DataTable dt = new DataTable();
  
          using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(pFilePath, false))
          {
  
              WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart;
              IEnumerable&lt;Sheet&gt; sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild&lt;Sheets&gt;().Elements&lt;Sheet&gt;();
              string relationshipId = sheets.First().Id.Value;
              WorksheetPart worksheetPart = (WorksheetPart)spreadSheetDocument.WorkbookPart.GetPartById(relationshipId);
              Worksheet workSheet = worksheetPart.Worksheet;
              SheetData sheetData = workSheet.GetFirstChild&lt;SheetData&gt;();
              IEnumerable&lt;Row&gt; rows = sheetData.Descendants&lt;Row&gt;();
  
              foreach (Cell cell in rows.ElementAt(0))
              {
                  dt.Columns.Add(GetCellValue(spreadSheetDocument, cell));
              }
  
              foreach (Row row in rows)
              {
                  DataRow tempRow = dt.NewRow();
  
                  for (int i = 0; i &lt; row.Descendants&lt;Cell&gt;().Count(); i++)
                  {
                      tempRow[i] = GetCellValue(spreadSheetDocument, row.Descendants&lt;Cell&gt;().ElementAt(i - 1));
                  }
  
                  dt.Rows.Add(tempRow);
              }
  
          }
          dt.Rows.RemoveAt(0);
      }
      public static string GetCellValue(SpreadsheetDocument document, Cell cell)
      {
          SharedStringTablePart stringTablePart = document.WorkbookPart.SharedStringTablePart;
          string value = cell.CellValue.InnerXml;
  
          if (cell.DataType != null &amp;&amp; cell.DataType.Value == CellValues.SharedString)
          {
              return stringTablePart.SharedStringTable.ChildElements[Int32.Parse(value)].InnerText;
          }
          else
          {
              return value;
          }
      }
  </code></pre>
  
  <p>But in <code>foreach (Row row in rows)</code> this condition I am getting an exception as <code>Specified argument was out of the range of valid values.
  Parameter name: index</code></p>