Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

.net save excel as stream

$
0
0

Hello,

I have an requirement to create a report in excel sheet and give the user to download the same in asp.net web application.

Currently i am saving the excel report on server and giving the user to download by taking the stream.

I am using excel object library 12.0

Is there any mechanism where i dont need to save the excel on server and directly send the stream?

below is my code:

Excel.

Application

xlApp;

Excel.

Workbook

xlWorkBook;

Excel.

Worksheet

xlWorkSheet;

 

object misValue = System.Reflection.Missing

.Value;

xlApp =

new Excel.Application

();

xlWorkBook = xlApp.Workbooks.Add(misValue);

xlWorkSheet = (Excel.

Worksheet)xlWorkBook.Worksheets.get_Item(1);

xlWorkSheet.Cells[1, 1] =

 

"Section 1";

xlWorkBook.SaveAs(

 

@"C:\temp\SampleApp\csharp-Excel.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

xlWorkBook.Close(

 

true

, misValue, misValue);

xlApp.Quit();

I then pass this path and get a stream and give prompt to user to download.

So can i avoid saving of excel on server and directly send a stream?



Thanks,

Seema

 
 
 
Seema Karia

Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>