When I've had to skin this cat, this is the approach that I took:
var stream = ExcelUtility.GetExcel(temp);
var filename = "MyFile.xlsx"
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = false,
};
Response.Clear();
Response.AppendHeader("Content-Disposition", cd.ToString());
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(stream.ToArray());
Response.Flush();
Response.End();
I suspect 2 possibilities.
First, without a proper Content-Disposition the browser isn't sure what to do with the file.
Second, the file may have issues since it is a text stream rather than a byte[]. You'd likely be best off building a function that leverages DocumentFormat.OpenXML to parse the grid, rather than trying to send it as a text stream.