Javascript Excel OpenFile

我有这个代码:

<html> <script type="text/javascript"> function test() { var Excel = new ActiveXObject("Excel.Application"); Excel.Workbook.Open("teste.xlsx"); } </script> <body> <form name="form1"> <input type=button onClick="test();" value="Open File"> <br><br> </form> </body> </html> 

所以主要的问题是我不断收到这个错误:

 On line 7 , Unable to get value of property Open URL file:///C:/users/admin/desktop/test.hta 

首先,尝试将脚本移动到身体的底部。 您还应该将您的Excelvariables设置为可见。 还有Excel.Workbook.Open("teste.xlsx");行的拼写错误Excel.Workbook.Open("teste.xlsx"); (应该是Workbooks )。 以下是在IE中为我工作。 我不认为它会在其他浏览器中工作:

 <html> <body> <form name="form1"> <input type=button onClick="test()" value="Open File"> <br><br> </form> <script type="text/javascript"> function test() { var Excel = new ActiveXObject("Excel.Application"); Excel.Visible = true; Excel.Workbooks.Open("teste.xlsx"); } </script> </body> </html>