title: Can I read Excel files using the OleDbConnection Excel ACE Driver from a non-seekable System.IO.Stream rather than a file?
body: <p>There's a similar question here <a href="https://stackoverflow.com/questions/908712/in-memory-oledbconnection-to-excel-file">In Memory OleDbConnection to Excel File</a> but, this question was answered by avoiding it completely by doing it another way.</p>
  
  <p>Here's some example code which uses an <code>OleDbConnection</code> to access an Excel file from disk:</p>
  
  <pre><code>static void Main(string[] args)
  {
      String filePathToExcelFile = "c:\\excelfile.xls";
      Boolean hasHeaders = true;
  
      String connectionString = String.Format(
          "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};" +
          "Extended Properties=\"Excel 12.0;HDR={1};IMEX=2\"",
          filePathToExcelFile, hasHeaders ? "Yes" : "No");
  
      using(OleDbConnection conn = new OleDbConnection(connectionString))
      using (OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", 
          conn))
      {
          conn.Open();
          OleDbDataReader datareader = command.ExecuteReader();
  
          while(datareader.Read())
          {
              Object[] values = new object[datareader.FieldCount];
              datareader.GetValues(values);
  
              Console.WriteLine(String.Join(",", values));
          }
      }
  }
  </code></pre>
  
  <p>I'd like to pull the Excel file from a NON-SEEKABLE <code>System.IO.Stream</code>, not a persistent file on the disk.  </p>
  
  <p>The question breaks down into two parts, a) Can I "point" the OleDbConnection to a System.IO.Stream? b) If so can that be a forward only stream rather than a seekable one?</p>
  
  <p>FYI: if you want to run this code snippet you'll need to install the <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=13255" rel="nofollow noreferrer">Microsoft Access Database Engine 2010 Redistributable</a>. And if you install the 64 bit one you'll need to target the project to be x64 and vice versa. </p>