简体   繁体   中英

Read an in-memory Excel file (byte array) with ADO.NET?

I want to use ADO.net to extract some data from an Excel file. This process is pretty well documented on the internet. My catch is that my file has been uploaded by a user, and so exists only as a byte array in memory. For security and performance reasons I would rather not write this file to disk.

Is there a way of constructing a connection string that connects to a byte array? Or perhaps exposing that array as a file that is actually stored in memory (like a RAM disk I guess)?

You can't connect if it only exists in memory. OLE is also ruled out (though using Office Automation for a server application is poor design to begin with).

The only way I can think of is to read the binary Excel data yourself - for example use SpreadSheetGear.Net with something like:

SpreadsheetGear.Factory.GetWorkbookSet().Workbooks.OpenFromStream(*stream*);

Like Rich B said in his answer, I do not think it is possible to connect in a standard ado.net way to an excel file that is just hanging around in memory. The simplest work-around would probably be to actually save the excel file to the disk, connect to it using the Jet engine with your connection string, and then when you are done performing all your tasks, get rid of the file. This may not be the ideal in terms of performance, but it is lacking that certain WTFiness which would cause you to pull your hair out.

I don't think it is possible to do this via just a connection string.

If you want help with an Excel file on disk: http://connectionstrings.com/excel-2007

In general: http://connectionstrings.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM