Click here to Skip to main content
12,448,219 members (51,570 online)
Rate this:
 
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.autofit;
    ExcelSheet.Application.Visible = true;
    DisplayAlerts = true;
    CollectGarbage();
}
Thanks & Regards
Posted 1-Aug-12 20:36pm
v2
Comments
Suvabrata Roy 2-Aug-12 2:39am
   
Hi,

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..

Thanks
gautamamit8 1-May-13 6:13am
   
Hi Suvabrata, pls send me the code as I need to complete this with AJAX.
Thanks in advance.
Amit
gautamamit8@gmail.com
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 : deepaligupta321@gmail.com
Thanks,
TS11 9-May-14 6:41am
   
please send me the code
thanks in advance
zulfiker.zli786@gmail.com
Member 12470111 25-Apr-16 3:54am
   
Hi Suvabrat,

Could you please send it to w.aburezeq@gmail.com

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.
Isabella
isabellakhinmaythu@gmail.com
Ravinder Singh Bhawer 25-Mar-14 0:50am
   
hi buddies ,
Please anybody send me code .
Thanks for the help in advance .
Email me at: rvsngh87@gmail.com
Member 10408402 21-Jun-14 8:18am
   
hi ...
please send me code ..
thanks for help
Email me : s.manunggal@gmail.com
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Following discussion should help: How to export html table to excel using javascript[^]
  Permalink  
Comments
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
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,

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.

[Update]

http://stackoverflow.com/questions/2274173/how-to-pull-data-and-export-to-excel-within-an-ajax-framework?answertab=votes#tab-top[^]
http://npoi.codeplex.com/[^]
  Permalink  
v2
Rate this: bad
 
good
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[^]

[Update] http://www.w3schools.in/jquery/export-to-excel/[^]

Enjoy Smile | :)
  Permalink  
v2
Comments
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.160811.3 | Last Updated 2 Nov 2015
Copyright © CodeProject, 1999-2016
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