Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open excel workbook from memorystream

Tags:

c#

.net

excel

I am trying to open an excel workbook from a memorystream. I have a web url of the excel file, what I do is I download the data from the url, then save it into a memorystream, but I am not sure how to open the workbook from the stream, here is how my code works so far.

WebClient wc = new WebClient();

byte[] fileArray = wc.DownloadData("url is inserted here");

MemoryStream ms = new MemoryStream(fileArray);

But from here I'm not sure how to go about reading the data from the stream to create the workbook, it doesn't seem like the spreadsheet document from http://msdn.microsoft.com/en-us/library/ff478410 works the way I want it to, any assistance or pointers would be appreciated

like image 904
afkmaster Avatar asked Jun 09 '12 01:06

afkmaster


People also ask

How do I download an Excel file into .NET core?

1. Right Click the Project in Solution Explorer and click Manage NuGet Packages from the Context Menu. 2. Now you will need to look for ClosedXML package and once found, you need to click the Install Button.

How do I convert workbook to stream?

Export an Excel File to Stream in C#Load the Excel file using Workbook class. Create a new FileStream object. Export Excel file to stream using Workbook. Save(FileStream, SaveFormat) method.


1 Answers

SpreadSheetDocument has an Open static method overload that takes stream as param for document source, just add to your code :

var doc = SpreadSheetDocument.Open(ms, isEditable);
like image 156
Antonio Bakula Avatar answered Sep 18 '22 06:09

Antonio Bakula