I am working on creating and downloading the excel file. When user clicks on the button, an excel file is filled with data retrieved from database and save the file over the server. At the same time I need to download the same excel file to the client. i.e.
User clicks the button, which will create and save an excel file over server and then after that download the file, without anyother click.
I have applied some JQuery tips to download the file after google, but nothing is working.
2. You should use a jQuery ajax call for invoking file filling and saving at the server and in the "success" function set the iframe src with the URL to teh excel file which will prompt the user for downloading it:
$.ajax({
type: 'POST',
url: 'ProcessExcelFile.ashx',
success: function (respose) {
$("#tmpFrame").attr('src', 'URL-TO-EXCEL-FILE');
},
error: function (result) {
alert('error');
}
});
});
Barcode, Labeling, Printing & Imaging tools for ASP.NET Developers
azharrahi
Member
127 Points
238 Posts
How to download excel file using JQuery
Nov 05, 2012 09:11 AM|LINK
Hope all will be fine here.
I am working on creating and downloading the excel file. When user clicks on the button, an excel file is filled with data retrieved from database and save the file over the server. At the same time I need to download the same excel file to the client. i.e. User clicks the button, which will create and save an excel file over server and then after that download the file, without anyother click.
I have applied some JQuery tips to download the file after google, but nothing is working.
Neodynamic
Participant
988 Points
283 Posts
Re: How to download excel file using JQuery
Nov 05, 2012 10:34 AM|LINK
You can use a hidden iframe to download the generated file. Something like teh following:
1. Create a hidden iframe in your page
2. You should use a jQuery ajax call for invoking file filling and saving at the server and in the "success" function set the iframe src with the URL to teh excel file which will prompt the user for downloading it:
$.ajax({ type: 'POST', url: 'ProcessExcelFile.ashx', success: function (respose) { $("#tmpFrame").attr('src', 'URL-TO-EXCEL-FILE'); }, error: function (result) { alert('error'); } }); });piyush.mall
Member
208 Points
41 Posts
Re: How to download excel file using JQuery
Nov 05, 2012 10:39 AM|LINK
use the follwoing code for downlaoding excel file at client:
function openExcelFile(strFilePath) { if (window.ActiveXObject) { try { var objExl; objExl = new ActiveXObject("Excel.Application"); objExl.Visible = true; objExl.Workbooks.Open(strLoc, false, [readonly: true|false]); } catch (e) { alert (e.message); } } else { alert ("Not able to download."); } }Anirudh.Gupt...
Member
633 Points
171 Posts
Re: How to download excel file using JQuery
Nov 05, 2012 11:05 AM|LINK
I think solution given by neoDynamic is more or less what you need. If you want to do it a bit more fancy try
http://jqueryfiledownload.apphb.com/
using ActiveXObjects will have browser support issues :)
asteranup
All-Star
30184 Points
4906 Posts
Re: How to download excel file using JQuery
Nov 06, 2012 02:16 AM|LINK
Hi,
You may check this post-
http://growingtech.blogspot.in/2012/10/export-html-to-excel-using-jquery-and.html
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog