【发布时间】:2019-11-15 22:26:09
【问题描述】:
我正在尝试创建一个简单的 webapp 按钮,它将在 Google 表格中复制表格,我在 HTML 中创建了该按钮并链接它以在单击时运行代码!但它似乎不起作用!谁能告诉我我做错了什么?
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<button id="btn">Create</button>
<script>
document.getElementById("btn").addEventListener("click",doStuff);
function doStuff(){
google.script.run.userClicked();
}
</script>
</body>
</html>
这里是复制代码:
function doGet() {
return HtmlService.createHtmlOutputFromFile('page');
}
function userClicked() {
SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
var myValue = SpreadsheetApp.getActiveSheet().getRange("M1").getDisplayValue();
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet("Daily Report " + myValue);
}
【问题讨论】:
-
在这种情况下,当您打开电子表格时,您将在服务器上打开它,因此活动工作表始终与 ss.getSheets()[0] 相同,它始终是最左侧的工作表。因此,最好使用 getSheetByName() 准确地确定您希望打开的工作表。
标签: dom google-apps-script google-sheets web-applications