gpt4 book ai didi

javascript - 从 Chrome 扩展程序运行 Google Apps 脚本

转载 作者:行者123 更新时间:2023-11-28 06:21:54 26 4
gpt4 key购买 nike

我是 Google Chrome 扩展程序开发新手,我想在单击扩展程序中的按钮时从扩展程序运行应用程序脚本。但我不知道该怎么做,我已经检查了指南,但无法理解这个想法。这是我的代码,

script.js

$(document).ready(function () {
$('#btnGet').click(function () {
$(document).load('https://script.google.com/macros/s/AKfycbwpkBW7qKZBeJ011C7j3le4vV8D0SEHu9709mWtEMzJgrJmHnaR/exec');
});
});

应用脚本

function doGet(e){
function newEntry() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var lr = sheet.getLastRow();
sheet.getRange(lr+1, 1, 1, 3).setValues([["First Name", "Last Name", "Email"]]);
Browser.msgBox("New Entry Added!");
}
}

我已成功从我的 script.js 运行代码,但我不确定如何从我的应用脚本运行代码。如何从我的应用程序脚本运行代码?

最佳答案

简短回答

而不是

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();

尝试

var id = 'spreadsheet-id'; //replace with your spreadsheet id
var sheetName = 'sheet name'; //replace with your sheet name.
var ss = SpreadsheetApp.openByID(id);
var sheet = ss.getSheetbyName(sheetName);

说明

当从电子表格调用脚本时,可以使用返回电子表格事件对象的方法。 doGet(e) 可以与电子表格交互,但您应该指定您要处理的电子表格。

引用文献

关于javascript - 从 Chrome 扩展程序运行 Google Apps 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35449469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com