我基本上修改了 UI google 文档中的 UI 以使其适应我的需要。我有一个从用户那里获取信息的面板,然后它应该替换模板中的一些单词,最后发送一封电子邮件。这是我到目前为止所写的。一切都很好,只是它使替换不起作用的部分不起作用 which(var Time = setValue(e.parameter.userName) 但我不确定是否正确或者我应该使用不同的东西。我尝试使用 var Time = emailTemplate。 replace("TIME",e.parameter.userName)); 但我收到参考错误,e 未定义且未运行。任何帮助,将不胜感激。
function onOpen() {
var subMenus = [{name:"test", functionName: "doGet"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu("texts", subMenus);}
function doGet() {
var doc = SpreadsheetApp.openById("SP ID");
var app = UiApp.createApplication().setTitle('TITLE1');
var grid = app.createGrid(10, 10);
grid.setWidget(0, 0, app.createLabel('Time PST'));
grid.setWidget(0, 1, app.createTextBox().setName('Time'));
grid.setWidget(1, 0, app.createLabel('Minutes have passed'));
grid.setWidget(1, 1, app.createTextBox().setName('Minutes'));
grid.setWidget(2, 0, app.createLabel('Enter Name'));
grid.setWidget(2, 1, app.createTextBox().setName('Name'));
// Create a vertical panel..
var panel = app.createVerticalPanel();
// ...and add the grid to the panel
panel.add(grid);
var button = app.createButton('Submit');
var handler = app.createServerHandler('b');
handler.addCallbackElement(grid);
button.addClickHandler(handler);
// Add the button to the panel and the panel to the application, then display the application app
panel.add(button);
app.add(panel);
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
}
function b() {
var doc = SpreadsheetApp.openById("SP ID");
var emailTemplate = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A1").getValue() ;
var address = "albdominguez25@gmail.com";
var Time = setValue(e.parameter.Time);
var emailSubject = "Subject";
emailTemplate = emailTemplate.replace("TIME",Time);
MailApp.sendEmail(address, emailSubject, emailTemplate);
Browser.msgBox("Your Email has been sent!");
// Clean up - get the UiInstance object, close it, and return
var app = UiApp.getActiveApplication();
app.close();
// The following line is REQUIRED for the widget to actually close.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
}