function sendEmails() {
const sheet = getSpreadsheetApp()
const sheetData = getSpreadsheetData(sheet).getValues();
const subjectline = "Weekly Breakdown for the week of - "
var subjectDate = Browser.inputBox('Please enter the date range for e-mail subject.', Browser.Buttons.OK_CANCEL);
if(Browser.Buttons.CANCEL = true) {
Browser.msgBox('The operation has been cancelled')
return;
}
const subject = subjectline + subjectDate
在下面的代码中,即使我通过在输入框中输入详细信息来单击“确定”,它也会给我相同的消息框并停止运行脚本。
Browser.inputBox 返回一个文本字符串。要查找是否按下了 Cancel 按钮,请使用以下命令:
if (subjectDate === 'cancel') {
使用 Ui.prompt() 可以更好地检测输入的响应以及按下的按钮。
这个:
if(Browser.Buttons.CANCEL = true) {
Browser.msgBox('The operation has been cancelled')
return;
}
应该是:
if(Browser.Buttons.CANCEL == true) {
Browser.msgBox('The operation has been cancelled')
return;
}
= is an assignment
== is a comparison
并尝试这个:
function sendEmails() {
const ss = SpreadsheetApp.getActive();
const sheet = ss.getSheetByName("Your Sheet Name")
const sheetData = sh.getDataRange().getValues();
const subjectline = "Weekly Breakdown for the week of - "
var subjectDate = Browser.inputBox('Please enter the date range for e-mail subject.', Browser.Buttons.OK_CANCEL);
if(Browser.Buttons.CANCEL == true) {
Browser.msgBox('The operation has been cancelled')
return;
}
const subject = subjectline + subjectDate
}
不确定这何时成为一种选择,但这现在对我有用:
var ui = SpreadsheetApp.getUi();
var name = ui.prompt('Name:', ui.ButtonSet.OK_CANCEL).getResponseText();
if(ui.Button.CANCEL) {
return;
}