Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Excel OpenFile

I have this code:

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

So the main problem is I keep getting this error:

On line 7 , Unable to get value of property Open
URL file:///C:/users/admin/desktop/test.hta
like image 974
PythonNewbie Avatar asked Feb 17 '23 07:02

PythonNewbie


1 Answers

Firstly, try moving your script to the bottom of the body. You should also set your Excel variable to be visible. And there's a typo with the line Excel.Workbook.Open("teste.xlsx"); (should be Workbooks). The following is working for me in IE. I don't think it will work in other browsers:

<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>
like image 147
Simon Adcock Avatar answered Feb 28 '23 01:02

Simon Adcock