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
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With