Hi
If your dataset is large, then you can try streaming the data to the user. Even if your dataset is larger, the streaming uses the same memory.
You can get the bytes of the Excel spreadsheet, or simply convert your data to a CSV, and then set the HTTP Response Type and stream it to the user.
sample:
byte[] reportDoc = GetExportExcel();
context.Response.ContentType = "application/vnd.ms-excel";
//set the content disposition header to force download
context.Response.AddHeader("Content-Disposition", "attachment;filename=" +
"Export.xls");
//write the file content byte array
context.Response.BinaryWrite(reportDoc);