Free Support Forum - aspose.com

Sample code for using Aspose cells in a visual webpart in sharepoint 2010

i have a requirement where i need to export data into excel on a link button click and send it to user. once i do that i am unable to click on any of the controls in the page like any button or link and no postback event is firing after that. below is the code i have used workbook.Save("Report" + DateTime.Now.ToString("ddMMyyyyhhmmtt") + ".xlsx", FileFormatType.Excel2007Xlsx, SaveType.OpenInExcel, HttpContext.Current.Response); //workbook.Save(this.Response, "Report" + DateTime.Now.ToString("ddMMyyyyhhmmtt") + ".xlsx",SaveType.OpenInExcel, new OoxmlSaveOptions());
                    HttpContext.Current.Response.End();

i use aspose cells 4.7.1.10


Hi,

Well your line of code (involving Aspose.Cells API with some older version (v4.7.1.x), i.e.., "workbook.Save("Report" + DateTime.Now.ToString("ddMMyyyyhhmmtt") + ".xlsx", FileFormatType.Excel2007Xlsx, SaveType.OpenInExcel, HttpContext.Current.Response);" is equal to the following lines of code without involving Aspose.Cells APIs to response the file on the client side:
e.g
//...........
MemoryStream tempStream = new MemoryStream();
workbook.Save(tempStream, xSaveOptions);
//You may change it accordingly if you are saving in XLS file format
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + workbook.FileName);
Response.Flush();
Response.BinaryWrite(tempStream.ToArray());
Response.End();

You may confirm it and use the above lines without involving Aspose.Cells's APIs to response the file on the client side and you will see the same behavior, so it is the behavior of Response Object.

If you feel the lines in bold (above) have different behavior than "workbook.Save()"
let us know.

Thank you.