我正在尝试提供一个菜单项,提示输入电子邮件地址,将Google工作表作为pdf报告发送电子邮件。我几乎在那里,但我在最后一行收到错误。
" GmailApp.sendEmail(电子邮件,主题,正文,{附件:[文件]});。"
错误内容如下 " ReferenceError:" email"没有定义。 (第76行,文件"代码")"
我在这一行上缺少什么来完成脚本以通过提示成功发送电子邮件输入?
function onOpen() {
var menu = SpreadsheetApp.getUi().createMenu('My menu')
menu.addItem('Clear sheet', 'bigFunction')
.addSeparator()
.addSubMenu(SpreadsheetApp.getUi().createMenu('Email Menu')
.addItem('Email PDF', 'subFunction1'))
.addToUi();
}
function bigFunction() { //replace 'Sheet2' with your actual sheet name
var sheet = SpreadsheetApp.getActive().getSheetByName('Testing');
var range = sheet.getRange("A4:P40");
var formulas = range.getFormulas();
for (var i in formulas) {
for (var j in formulas[i]) {
Logger.log(formulas[i][j]);
sheet.getRange('A4:P40').clearContent();
var cell = sheet.getRange("A4:P40");
cell.setFormulas(formulas);
}
}}
function subFunction1() {
// Send the PDF of the spreadsheet to this email address
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Please input email address', ui.ButtonSet.YES_NO);
// Gets the URL of the currently active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var url = ss.getUrl();
url = url.replace(/edit$/,'');
// Subject of email message
// The date time string can be formatted using Utilities.formatDate method
// see examples at https://developers.google.com/apps-script/reference/utilities/utilities#formatdatedate-timezone-format
// and http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
var subject = "Geico Tracker Report - " + Utilities.formatDate(new Date(), "GMT", "dd-MMM-yyyy");
// Body of email message
var body = "\nDaily Geico Tracker Report.\n \n";
/* Specify PDF export parameters
// Taken from: code.google.com/p/google-apps-script-issues/issues/detail?id=3579
exportFormat = pdf / csv / xls / xlsx
gridlines = true / false
printtitle = true (1) / false (0)
size = A4 / letter /legal
fzr (repeat frozen rows) = true / false
portrait = true (1) / false (0)
fitw (fit to page width) = true (1) / false (0)
add gid if to export a particular sheet - 0, 1, 2,..
*/
var url_ext = 'export?exportFormat=pdf' // export as pdf
+ '&format=pdf' // export as pdf
+ '&size=letter' // paper size
+ '&portrait=false' // page orientation
+ '&fitw=true' // fits width; false for actual size
+ '&sheetnames=false' // hide optional headers and footers
+ '&printtitle=false' // hide optional headers and footers
+ '&pagenumbers=false' // hide page numbers
+ '&gridlines=false' // hide gridlines
+ '&fzr=false' // do not repeat row headers
+ '&gid=0'; // the sheet's Id
var token = ScriptApp.getOAuthToken();
// Convert worksheet to PDF
var response = UrlFetchApp.fetch(url + url_ext)
//convert the response to a blob
file = response.getBlob().setName('Geico Tracker.pdf');
// Send the email with the PDF attachment. Google sets limits on the number of emails you can send: https://docs.google.com/macros/dashboard
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(email, subject, body, {attachments:[file]});
}