我在Google工作表中有一个脚本会将当前工作表作为附件发送到电子邮件。
该脚本100%的时间适用于我,但其他任何运行相同内容的人都会收到错误。寻找想法或解决方案,这样每个人都可以使用脚本而不仅仅是我。他们都已授权脚本运行,但仍然是同样的错误。 (脚本下面列出的错误)
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Send Email')
.addItem('Course Update', 'menuItem1')
.addItem('Training Week Email', 'menuItem2')
.addToUi();
}
function menuItem1() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
COURSEUPDATE();
}
function menuItem2() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
TRAININGWEEK();
};
//This is the second Script to send entire doc to me
function COURSEUPDATE() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// Email subject and message body
var url = ss.getUrl();
url = url.replace(/edit$/,'');
var url_ext = 'export?exportFormat=pdf&format=pdf' // export as pdf
+ '&size=letter' // paper size
+ '&portrait=false' // orientation, false for landscape
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenumbers=false&gridlines=false' // hide pagenumbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&gid='; // the sheet's Id
var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();
var response = UrlFetchApp.fetch(url + url_ext + SpreadsheetApp.getActiveSheet().getSheetId(), {
headers: {
'Authorization': 'Bearer ' + token
}
});
var email = SpreadsheetApp.getActiveSheet().getRange("A3").getValue();
var message = "Versal Course Updates";
var subject = "Versal Course Progress Updates";
MailApp.sendEmail(email, subject, message, {attachments:[response]});
};
//Traiing Week Email
function TRAININGWEEK() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// Email subject and message body
var url = ss.getUrl();
url = url.replace(/edit$/,'');
var url_ext = 'export?exportFormat=pdf&format=pdf' // export as pdf
+ '&size=letter' // paper size
+ '&portrait=true' // orientation, false for landscape
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenumbers=false&gridlines=false' // hide pagenumbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&gid='; // the sheet's Id
var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();
var response = UrlFetchApp.fetch("url + url_ext + SpreadsheetApp.getActiveSheet().getSheetId(), {
headers: {
'Authorization': 'Bearer ' + token
}
});
var email = SpreadsheetApp.getActiveSheet().getRange("A3").getValue();
var message = "Training Information";
var subject = "Stratus Training Information";
MailApp.sendEmail(email, subject, message, {attachments:[response]});
};
其他人正在收到错误,每次都能成功为我效力:
答案 0 :(得分:0)
添加一行
DriveApp.getRootFolder()
您需要调用一次才能获得OAuthtoken。对于失败的请求,它可能是空的。