When using our C Sharp .NET Excel API, GcExcel, in an MVC some users may want an Excel file to be downloaded within the Browser and not to their local drive. Users can accomplish this by creating a response with headers and writing the stream of the workbook to it.
We must first create a memory stream and then using GcExcel’s save method we will save the created workbook to a stream. Be sure to reset the stream to its original position after saving:
Then we will write a response with headers and write the memory stream to the response:
After applying this code logic and running the MVC (ASP.NET) project, the excel file is downloaded to the browser like so: