Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an Excel workbook to a MemoryStream in .NET?

Tags:

.net

excel

How do I write an Excel workbook to a MemoryStream without first saving it to the file system?

All options within the Microsoft.Office.Interop.Excel.WorkBook save options take a filename.

like image 750
Jon Cahill Avatar asked Oct 01 '08 06:10

Jon Cahill


People also ask

How do I automatically link data in Excel?

Go to Sheet2, click in cell A1 and click on the drop-down arrow of Paste button on the Home tab and select Paste Link button. It will generate a link by automatically entering the formula =Sheet1! A1 .

How do you make an Excel File downloadable?

Select File > Save As > Download a Copy. If Excel asks whether to open or save the workbook, select Save. Note: If you select Open instead of Save, the workbook will open in Protected View. Depending on your browser, you may not be asked this.


1 Answers

I have done extensive work with the PIA and with storing Excel files in a document repository and streaming it out to the browser, and I have not been able to find a solution to using the PIA without first writing the contents to the file system first.

I think that you are going to have to swallow the bullet and deal with the file system as an intermediary. The good news is that you can just give the file a unique name like a guid or use some other tempfilename method (not sure if one exists in .net) and just delete the contents when you are done.

like image 171
Charles Graham Avatar answered Sep 22 '22 18:09

Charles Graham