0

我觉得我要疯了,试图让最简单的事情发挥作用!我在 Google Drive 上的 Google 电子表格中有一个邮件列表。我创建了一个用户界面,提示输入用户想要包含在电子邮件中的消息。我的代码看起来像这样。

function startBulkEmailUI(e) {
  //create main form
  var app = UiApp.createApplication().setTitle('Send Email').setWidth(602).setHeight(402);
  var scrollPanel = app.createScrollPanel().setId('scrollPanel').setAlwaysShowScrollBars(true) ;
  var mainPanel = app.createVerticalPanel().setId('mainPanel');
  mainPanel.setStyleAttribute('border', '1px solid #C0C0C0').setWidth("100%").setHeight("100%");
  scrollPanel.add(mainPanel);
  //create panel for input boxes etc
  var inputPanel =     app.createVerticalPanel().setId('inputPanel').setWidth("100%").setHeight("100%").setSpacing(0);
  var messageLabel = app.createLabel('E-mail Message');
  var messageBox = app.createTextArea().setName('messageBox').setId('messageBox').setVisible(true).setWidth(400).setHeight(150);
  var attachmentLabel = app.createLabel('E-mail Attachment');
  var attachmentCheckBox = app.createCheckBox('Attach a file').setValue(false);
 inputPanel.add(messageLabel).add(messageBox).add(attachmentLabel).add(attachmentCheckBox);
  mainPanel.add(inputPanel).setCellHorizontalAlignment(inputPanel, UiApp.HorizontalAlignment.CENTER) ;
  inputPanel.setCellHorizontalAlignment(messageLabel, UiApp.HorizontalAlignment.CENTER);
  inputPanel.setCellHorizontalAlignment(messageBox, UiApp.HorizontalAlignment.CENTER);
  inputPanel.setCellHorizontalAlignment(attachmentLabel, UiApp.HorizontalAlignment.CENTER);
  inputPanel.setCellHorizontalAlignment(attachmentCheckBox, UiApp.HorizontalAlignment.CENTER);
  //add function buttons
  var buttonsPanel = app.createHorizontalPanel().setStyleAttribute('margin', '20px').setWidth(500);
  var closeButton = app.createButton('Close',app.createServerHandler('close_'));
  var sendButton = app.createButton('Send!').setId("sendButton");
  buttonsPanel.setId('buttonsPanel').add(closeButton).add(sendButton);
  mainPanel.add(buttonsPanel).setCellHorizontalAlignment(buttonsPanel, UiApp.HorizontalAlignment.CENTER);
  buttonsPanel.setCellHorizontalAlignment(closeButton, UiApp.HorizontalAlignment.CENTER).setCellHorizontalAlignment(sendButton, UiApp.HorizontalAlignment.CENTER);
  app.add(scrollPanel);
  //handlers
  var handlerSendEmails = app.createServerClickHandler('sendEmails');
  handlerSendEmails.addCallbackElement(inputPanel);
  sendButton.addClickHandler(handlerSendEmails);

  //show the form
  ss.show(app);

  return app;
}

function sendEmails(e) {
  var contactDetail = getContactDetail();
  var count = 0;
  var failed = 0;
  for (i in contactDetail) {
  var row = contactDetail[i];
  var emailAddress = row[9];

  var stuff = e.parameter.messageBox.value;
  Logger.log(e.parameter);
  var message = 'Hi, ' + row[4] + '\n\n' + 'This is a test!';       // Second column
  var subject = 'Test Email';
  try {
//      MailApp.sendEmail(emailAddress, subject, message);
      count = count+1;
    } catch(e) {
      failed = failed+1;
    }
  }
  var msg = stuff;
  Browser.msgBox('Debug Msg', msg, Browser.Buttons.OK);
}

我希望用户在 textarea 中输入信息,然后我可以将其用作电子邮件的正文。我发现没有 getText,所以我找到了数百个答案说它应该看起来像上面的代码:你创建一个回调处理程序,然后使用 e.parameter.OBJECT_NAME.value 来获取文本。它根本不适合我,我已经尝试了我能想到的所有解决方法。有什么建议么?我的代码有问题吗(我知道它很乱……)?

4

1 回答 1

0

在处理函数中获取小部件值的“正常”方式是在表单中,e.parameter.widgetName所以在你的情况下你应该简单地使用

var stuff = e.parameter.messageBox; 没有 ".value" ,结果是一个字符串。

于 2013-03-24T07:44:13.753 回答