Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

c# reading varbinary or byte[] to .xlsx

Posted on 2012-08-22
2
Medium Priority
?
1,762 Views
Last Modified: 2012-08-24
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!
0
Comment
Question by:HyperBPP
2 Comments
 
LVL 6

Author Comment

by:HyperBPP
ID: 38322647
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?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 38325538
1) How slow?

2) You should be able to combine 2 statements, but I don't think that it would help much:

    MemoryStream excelMemStream = new MemoryStream(fileBinary);

Open in new window

0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question