Click here to Skip to main content
11,636,889 members (76,669 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
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 at 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 at 2-Aug-12 2:41am
ya please send me that..

gautamamit8 at 1-May-13 6:13am
Hi Suvabrata, pls send me the code as I need to complete this with AJAX.
Thanks in advance.
nicks2 at 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 at 9-May-14 6:41am
please send me the code
thanks in advance
Member 8273312 at 2-Aug-12 2:56am
yes please...
Member 10304510 at 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 at 25-Mar-14 0:50am
hi buddies ,
Please anybody send me code .
Thanks for the help in advance .
Email me at:
Member 10408402 at 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 at 2-Aug-12 2:56am
I have used almost same code ..
Sandeep Mewara at 2-Aug-12 3:36am
Almost or exact? What happens when you do as it says?
Member 8273312 at 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 at 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 Smile | :)
ThePhantomUpvoter at 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 at 29-Aug-13 8:50am
there was a comment thats why i posted again..
ThePhantomUpvoter at 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 at 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
0 263
1 stibee 249
2 Sergey Alexandrovich Kryukov 229
3 Suvendu Shekhar Giri 225
4 OriginalGriff 183
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,493
2 Mika Wendelius 6,909
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320

Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 29 Aug 2013
Copyright © CodeProject, 1999-2015
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