您可以使用 Properties Service 的 Apps 脚本。
此服务允许脚本将字符串存储为范围内的键值对
一个脚本、一个脚本的用户或一个文档,其中
使用了编辑器插件。
在您的情况下,您可以选择 2 个选项。 脚本属性和用户属性。
两者的区别在于脚本属性的内容是共享给所有用户的,而用户属性只对脚本的当前用户可用,插件,或网络应用程序。
这里我创建了一个如何使用属性的示例。
function setProperties(lastName = "Test Last Name", email = "Test Email", phone = "Test Phone"){
var scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({'lastName': lastName, 'email': email, 'phone':phone})
}
function readProperties(){
var scriptProperties = PropertiesService.getScriptProperties();
Logger.log(scriptProperties.getProperties());
}
这里我先运行readProperties()函数,结果是
然后我运行 'setProperties()' 并再次重新运行 readProperties() 函数:
我重新加载脚本页面并运行readProperties() 函数:
要将其添加到您的脚本中,您可以在AddUserInputToSheet() 中设置属性并在脚本中的任何位置调用它。
例子:
function AddUserInputToSheet(gender, firstName, lastName, age, email, phone) {
var url = 'SHEET_URL';
var ss = SpreadsheetApp.openByUrl(url);
var webAppSheet = ss.getSheetByName("SHEET_NAME");
webAppSheet.appendRow([gender, firstName, lastName, age, email, phone]);
var scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({'lastName': lastName, 'email': email, 'phone':phone})
}
function someFunction(){
var scriptProperties = PropertiesService.getScriptProperties();
var data = scriptProperties.getProperties();
var lastName = data["lastName"];
var email = data["email"];
var phone = data["phone"];
//some operations here
}