javascript - 如何打开本地 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>
此代码中的按钮单击在电子中不起作用。
解决方案
只需在 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>
推荐阅读
- php - 使用 Laravel 操作数据库数据而不使用迁移
- javascript - 显然 JSON.parse 比声明一个对象字面量要快。如果是这样,为什么我的结果会显示其他结果?
- javascript - 是否可以将系统输出放入 javascript 中的 var 中?
- javascript - Kendo UI 如何将参数传递给模态?
- python - Azure REST API 消耗:puid 为空/空
- angular - Angular 安装要求 Angular 团队提供匿名使用数据
- google-bigquery - 过滤掉社区连接器中的无效数据
- c++ - 使用 GridFS 对 mongocxx(mongodb c++ 驱动程序)的 MD5 支持
- python - 如何区分 Python 日志记录中的文件和子模块?
- google-app-engine - 在灵活的 Google App Engine 上,什么会使用 s-maxage 缓存响应以及如何清除该缓存?