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

心不动则不痛 提交于 2019-12-10 14:24:06

问题


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)?


回答1:


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*);



回答2:


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.




回答3:


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/



来源:https://stackoverflow.com/questions/920556/read-an-in-memory-excel-file-byte-array-with-ado-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!