# Web Development > JavaScript Export to excel

## paritosh.garg

Hi,
   i am designing the webpage, where i have a page with search results that are dynamic (based on some input from the user, search is performed) ..
  i want to export these results to Excel..
can any body help me..
i tried the following code:


                        var oXL = new ActiveXObject("Excel.Application");	

		oXL.Visible = true;

				   // Get a new workbook.
		var oWB = oXL.Workbooks.Add();
		var oSheet = oWB.ActiveSheet;


the code is working on my local machine..
but when i tried to load the webpage on server and then tried to run from my local machine...its giving error::

Automation Server can not create object..

Please let me know...if there is any other way to export to Excel...using java script...

----------


## prafullagang

Hi

I tried using your Javascript; but it did not run on local machine except opening the excel file.

I tried two scripts:





Is there any error in the script?

regards / Prafulla

----------


## prafullagang

Script 1

    Function ExportToExcel()

        Var sHTML = document.all.item("table1").outerhtml;
        Var oExcel = new ActiveXObject("Excel.Application");
        Var oBook = oExcel.Workbooks.Add;
        sHTML = oBook.HTMLProject.HTMLProjectItems("Sheet1").Text;
        oBook.HTMLProject.RefreshDocument;
        oExcel.Visible = true;
        oExcel.UserControl = true;
    End Function


Script 2

function Export() { 
window.clipboardData.setData(Text,document.all(table2').outerHTML); 
try{ 
var ExApp = new ActiveXObject(Excel.Application); 

var ExWBk = ExApp.workbooks.add();
var ExWSh = ExWBk.worksheets(1); 
ExApp.visible = true; 
ExApp.DisplayAlerts = true; 

}catch(e){ 
alert(your computer dont install Microsoft Excel!) 
return false 
} 
ExWBk.worksheets(1).Paste; 
}
oExcel.Visible = true;
oExcel.UserControl = true; 


Sorry for reposting, as the script tag perhaps disallowed on the forum.

----------

