Javascript Excel OpenFile

前端 未结 2 1635
渐次进展
渐次进展 2020-12-07 03:07

I have this code:


  

        
相关标签:
2条回答
  • 2020-12-07 04:02

    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>
    
    0 讨论(0)
  • 2020-12-07 04:08

    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 讨论(0)
提交回复
热议问题