Click here to Skip to main content
13,003,102 members (57,496 online)
Rate this:
Please Sign up or sign in to vote.
Hi All ,
I want to export html table to excel using JavaScript and i am done .
But when i am exporting it is directly showing to excel page, actually i want it to first it should show a dialog box with "Open","Save" and "Cancel" option . But i am not able to find the solution . please help me out for this .
JavaScript code is given below :
function write_to_excel() {
    str = "";
    var mytable = document.getElementById("tbExport");
    var rowCount = mytable.rows.length;
    var colCount = mytable.getElementsByTagName("tr")[0].getElementsByTagName("th").length;
    var ExcelApp = new ActiveXObject("Excel.Application");
    var ExcelSheet = new ActiveXObject("Excel.Sheet");
    //ExcelSheet.Application.Visible = true;
    for (var i = 0; i < rowCount; i++) {
        for (var j = 0; j < colCount; j++) {
            if (i == 0) {
                str = mytable.getElementsByTagName("tr")[i].getElementsByTagName("th")[j].innerText;
            else {
                str = mytable.getElementsByTagName("tr")[i].getElementsByTagName("td")[j].innerText;
            ExcelSheet.ActiveSheet.Cells(i + 1, j + 1).Value = str;
    ExcelSheet.Application.Visible = true;
    DisplayAlerts = true;

Thanks & Regards
Posted 1-Aug-12 20:36pm
Suvabrata Roy 2-Aug-12 2:39am

Please don't use Active X Control directly from your web page.
some antivirus will black list your site.

you can use Ajax request...
do you need the code
Member 8273312 2-Aug-12 2:41am
ya please send me that..

gautamamit8 1-May-13 6:13am
Hi Suvabrata, pls send me the code as I need to complete this with AJAX.
Thanks in advance.
nicks2 29-Aug-13 2:07am
Hi Suvabrata ,can You please send me the same code ? I also want to export mt html table data to excel file witout using active X Control.
EmailID :
TS11 9-May-14 6:41am
please send me the code
thanks in advance
Member 12470111 25-Apr-16 3:54am
Hi Suvabrat,

Could you please send it to

Thank you,
Member 8273312 2-Aug-12 2:56am
yes please...
Member 10304510 17-Jan-14 1:04am
hi Suvabrata, pls send me the code as I need to complete this with ajax . Thanks in advance.
Ravinder Singh Bhawer 25-Mar-14 0:50am
hi buddies ,
Please anybody send me code .
Thanks for the help in advance .
Email me at:
Member 10408402 21-Jun-14 8:18am
hi ...
please send me code ..
thanks for help
Email me :
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Following discussion should help: How to export html table to excel using javascript[^]
Member 8273312 2-Aug-12 2:56am
I have used almost same code ..
Sandeep Mewara 2-Aug-12 3:36am
Almost or exact? What happens when you do as it says?
Member 8273312 2-Aug-12 3:48am
It is working perfectly .Actually that excel sheet opening directly without asking to "Open","Save" and "Cancel" .
I want it should show first dialog box where it will ask for open,save and cancel and then we choose a option .
Suvabrata Roy 9-May-14 8:48am
write you custom code before opening of the file and follow the command.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


This link will help you in creating Excel via ASP.

9 Solutions to Export Data to Excel for ASP.NET[^]

Now create a Asp page where you will send a Http X request to that particular page

and get the response and write it on a javascript popup.

If any problem revert me.

Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Hi All,

First create a page where you will generate that file using your business logic.

Use this script as they assist : Link[^]


Enjoy :)
ThePhantomUpvoter 29-Aug-13 6:27am
Really? You answered this over a year ago and now you are answering again? Why? Do you really think that he is still having the same problem from a year ago? Why not simply update your previous answer if you had some more information?
Suvabrata Roy 29-Aug-13 8:50am
there was a comment thats why i posted again..
ThePhantomUpvoter 29-Aug-13 10:20am
And? So why did you not update your existing answer then? Why reply to the OP and not reply to the commenters? Do you think that they got a notification?
Suvabrata Roy 29-Aug-13 12:02pm
Yes, I dont know if i modify the same solution then they may dont get any notification so I add another solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 2 Nov 2015
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100