views:

505

answers:

3

I would like to open an OleDbConnection to an Excel file that's in memory as a FileStream. Does anyone know if this is possible and how to accomplish it?

Big picture I would like to pass the file bytes into a .NET CLR Stored Procedure and extract the data. Perhaps there's a better way to do this that I've not considered.

Thanks in advance.

A: 

You can extract the data using VSTO. It has an object model for Excel. Then pass what you want to the proc. I think that would be better than trying to have the CLR stored proc decipher an Excel file stream.

JP Alioto
+1  A: 

The VSTO solution JP offers is definitely viable. However, if you really want to use OleDb and some SQL, take a look at this artcile: it's a MS knowledge base article that describes how to import data from excel into SQLSever using OleDb.

Esteban Araya
Esteban, excellent article. However, of all the method mentioned appear to rely on the Excel file being persisted to disk. Any idea how these techniques could be utilized to attach to an in-memory Excel file or Blob column?Thanks.
javacavaj
@Steve: I don't know, but I don't think so.
Esteban Araya
A: 

You can use SpreadsheetGear to open a file from a byte array in memory or from any stream with SpreadsheetGear.Factory.GetWorkbookSet().Workbooks.OpenFromMemory(byte[]) / OpenFromStream(System.IO.Stream).

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson