Link to home
Start Free TrialLog in
Avatar of HyperBPP
HyperBPP

asked on

c# reading varbinary or byte[] to .xlsx

I am working with a c# in visual studio 2010 and MS SQL Server 2008 R2.

Another application is inserting .xlsx files into an SQL table as varbinary(max).  I need to pull these from the table and read the contents as if they are .xlsx files.

First, do I read these as byte[] to get the varybinary out of the database?

Then, once I have my file binary/byte string how to I convert this to a file that can be read as an excel workbook in C# with the SpreadsheetDocument class (using DocumentFormat.openxml, openxml.packaging, and openxml.spreadsheet).

Thanks!
Avatar of HyperBPP
HyperBPP

ASKER

Figured it out (assumes fileBinary from database):

MemoryStream excelMemStream = new MemoryStream();

excelMemStream.Write(fileBinary, 0, fileBinary.Length);

 SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(excelMemStream, false);

Although, this seems slow.  Anyone know faster solution?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial