Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone tell me the error in this code.Browser shows an error"automation server can't create object" and browser becomes hang Or tell me how to easily read excel sheet via javascript?????

<html> 
<head>
<title>excel</title>
    <script type="text/javascript"> 
        function my_function()
        {
             var Excel;
            Excel = new ActiveXObject("Excel.Application");	
            Excel.Visible = false;
            a=Excel.Workbooks.Open("C:/desktop/test2.xls").ActiveSheet.Cells(l,i).Value
            //Excel.Quit()
            return a;
        }		
    </script>  
</head>

<body>
    <script type="text/javascript">
        l=1,i=1;
        func()
        function func()
        {
            x=my_function()
            while(x!=null)
            {
                document.write("value is "+x+"\t")
                i++
                x=my_function()
            }
        }
        l++
        i=1
        func()
    </script>
</body>
</html>
Posted
Updated 10-Jun-10 23:59pm
v4

1 solution

I googled it, and found this:

<html>
<script>
function mytest1() 
{
	var Excel, Book;	// Declare the variables
	Excel = new ActiveXObject("Excel.Application");	// Create the Excel application object.
	Excel.Visible = false;	// Make Excel invisible.
	Book = Excel.Workbooks.Add()	// Create a new work book.
	Book.ActiveSheet.Cells(1,1).Value = document.all.my_textarea1.value;
	Book.SaveAs("C:/pathToFile/TEST.xls");		
	Excel.Quit();	// Close Excel with the Quit method on the Application object.
}

function mytest2() 
{
	var Excel;
	Excel = new ActiveXObject("Excel.Application");	
	Excel.Visible = false;
	form1.my_textarea2.value = Excel.Workbooks.Open("C:/pathToFile/TEST.xls").ActiveSheet.Cells(1,1).Value;
	Excel.Quit();
}

</script>

<body>
<form name="form1">
	<input type=button onClick="mytest1();" value="Send Excel Data"><input type=text name="my_textarea1" size=70 value="enter ur data here">
	<br><br>
	<input type=button onClick="mytest2();" value="Get Excel Data"><input type=text name="my_textarea2" size=70  value="no data collected yet">

</form>
</body>
</html>


If that doesn't help you, you can use google too. It's available in every country that has an internet connection.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900