We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Export to Excel for user


Once I have a grid displayed on a web page, my users want a button that will export the grid as seen on the web page into an Excel file for them to save locally i.e. I don't want to save to a file or stream on the server side.

How do I do this?



Yes you may do it. You can write lines of code in GridWeb_SaveCommand event handler. So when you click on the save button(icon) on the control you can save it locally on the client.


private void GridWeb1_SaveCommand(object sender, System.EventArgs e)
// Generates a temporary file name.
string filename = System.IO.Path.GetTempPath() + Session.SessionID + ".xls";
// Saves to the file.
// Sents the file to browser.
Response.ContentType = "application/vnd.ms-excel";
//Adds header.
Response.AddHeader( "content-disposition","attachment; filename=book1.xls");
// Writes file content to the response stream.
// OK.
Thank you.

Great, thanks Amjad.

That worked a treat! :)