最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript Excel OpenFile - Stack Overflow

programmeradmin5浏览0评论

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

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
Share Improve this question edited Sep 8, 2022 at 2:29 Marco Faustinelli 4,2166 gold badges39 silver badges53 bronze badges asked Mar 6, 2013 at 12:01 PythonNewbiePythonNewbie 2281 gold badge4 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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>

This work with IE 11 and you have to enable all the ActiveX controls in the Internet options. This will open the excel and open the exact sheet what you mentioned in the sheet name.

<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("c:\\jeba\\sample.xlsx");  
    var excel_sheet = Excel.Worksheets("sheetname_1");  
    excel_sheet.activate();  
  }   
</script>

发布评论

评论列表(0)

  1. 暂无评论