Reputation: 45
I want to open Excel from byte[]
because my file is encrypted and I want to open after decrypt but without write in a file.
The office has "restricted access" and I want to open my file with this protection but without saving the decrypted content in a file.
myApp.Workbooks.Open
only supports a path.
Is it possible?
Upvotes: 2
Views: 6617
Reputation: 1133
It is not possible because the interop
is actually an interface for programs to run and operate existing excel on the computer.
I think you need to use openxml
created by Microsoft to work with excel word and PowerPoint.
Then you can use:
ExcelPackage excelPackage = new ExcelPackage(stream)
or
var pck = new OfficeOpenXml.ExcelPackage();
pck.Load(File.OpenRead(path));
pck.Load(Stream)
can use any stream as input not only from a file.
It depends on your needs.
Upvotes: 1
Reputation: 170
As an alternative to OpenXml there's also ExcelDataReader which from my experience is a lot faster in processing data compared to Interop.Excel(around 3 times+).
It can also open encrypted Excel files directly(stackoverflow) The github page for ExcelDataReader has some great examples on how to use it. The only thing you'd have to do is:
using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
using (var stream = new MemoryStream(yourByte[])
And if you just want to open the password protected excel file you'd do this:
var conf = new ExcelReaderConfiguration { Password = "yourPassword" }; //Add this
excelReader = ExcelReaderFactory.CreateReader(stream, conf); //change the excel Reader to this
Make sure to check the Github page for more info!
Upvotes: 2