首页 > 解决方案 > 如何打开本地 Excel 工作表以在电子中单击按钮进行编辑?

问题描述

我正在使用电子开发一个应用程序,在该应用程序中我需要在按钮单击时打开一个本地 excel 文件

<html>
      <script type="text/javascript">
      function test() {
      var Excel = new ActiveXObject("Excel.Application");
      Excel.Visible = true;
      Excel.Workbooks.Open("C:/Users/Lenovo/.electron/test.xlsx");
     }
     </script>

     <body>

         <form name="form1">
         <input type=button onClick="test();" value="Open File">
         <br><br>
         </form>

     </body>
</html>

此代码中的按钮单击在电子中不起作用。

标签: javascripthtmlelectron

解决方案


只需在 html 页面中添加此代码并使用电子消息通信即可执行此操作

<form name="form1">
  <input type=button onClick="test()" value="Open File">
</form>



 <script type="text/javascript">
      function test() {
        var Excel = new ActiveXObject("Excel.Application");
        Excel.Visible = true;
        Excel.Workbooks.Open("teste.xlsx");
      }
    </script>

推荐阅读