2

Well, in my project I need to use an excel file to read data from it (yes, a propper database would be better, but I cannot use one).

With Microsoft.Office.Interop.Excel I open files like this:

Application.Workbooks.Open(FileName);

But I don't want to send that file along with the project DLL, because users are not meant to change this file.

So, I added it as a resource, and it became a byte array, with no path to disk.

byte[] ExcelFile = Properties.Resources.MyExcelFileResource;

Now, how do I load this byte array file with excel interop??? I want to open it properly as a real excel file, to work with it internally.

Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
  • That's not possible, Excel has no idea how to look in your DLL to read a .NET resource. It needs to be a file on disk. – Hans Passant May 22 '13 at 21:58
  • Hey, the byte array is a file. It's me who will indicate it to excel. – Daniel Möller May 22 '13 at 22:07
  • Some people are saving this byte array to disk and then opening it. It's a solution, but not a good one. – Daniel Möller May 22 '13 at 22:39
  • 1
    See [Open Excel Workbook file Using Embedded Resource](http://stackoverflow.com/questions/8083473/open-excel-workbook-file-using-embedded-resource) and [Load excel file from resources/assembly in C#](http://stackoverflow.com/questions/16205252/load-excel-file-from-resources-assembly-in-c-sharp) – Andy Brown May 23 '13 at 17:27
  • 1
    Also see a possible solution in [the answer](http://stackoverflow.com/a/9345609/1945631) to [c# using excel file from embedded resource](http://stackoverflow.com/questions/9344726/c-sharp-using-excel-file-from-embedded-resource) that uses a third party package called "Excel Package Plus" which apparently supports loading from stream. – Andy Brown May 23 '13 at 17:32

0 Answers0