我对脚本非常陌生,我希望在google电子表格上获得一个非常简单的脚本,以便在每次触发时创建一个1到150个奇数的随机数列。
问题是无论我在脚本框中放置什么来实际运行,它总是会出现:
此脚本的OAuth标识已被删除或禁用。这可能是由于服务条款违规造成的。
经过一些谷歌搜索后,我发现问题与脚本的身份验证有关,但即使我运行以下教程脚本,我也会遇到同样的错误:
function createAndSendDocument() {
// Create a new Google Doc named 'Hello, world!'
var doc = DocumentApp.create('Hello, world!');
// Access the body of the document, then add a paragraph.
doc.getBody().appendParagraph('This document was created by Google Apps Script.');
// Get the URL of the document.
var url = doc.getUrl();
// Get the email address of the active user - that's you.
var email = Session.getActiveUser().getEmail();
// Get the name of the document to use as an email subject line.
var subject = doc.getName();
// Append a new string to the "url" variable to use as an email body.
var body = 'Link to your doc: ' + url;
// Send yourself an email with a link to the document.
GmailApp.sendEmail(email, subject, body);
}
答案 0 :(得分:0)
Per @Zig Mandel-这是一个错误
这是一个可以帮助您的随机数字脚本。
function ranNum() {
// assume the array starts in A1 and runs down colA
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// getValues() returns an array
var range = sheet.getRange(1,1,sheet.getLastRow(),1).getValues();
var num = "";
num += Math.floor(Math.random() * 150 + 1);
// Loop through every element in the range
for(var j in range) {
if(range[j].toString() == num) {
Logger.log('matched');
} else {
// Write one code to the next line and stop the loop
sheet.getRange((sheet.getLastRow()+1), 1).setValue(num);
break
}
}
}