从textarea获取文本

时间:2013-03-24 07:05:40

标签: textbox google-apps-script

我觉得我疯狂地试图让最简单的事情发挥作用!我在Google云端硬盘上的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,所以我发现有数百个答案说它应该看起来像上面的代码:你创建一个callbackhandler,然后使用e.parameter.OBJECT_NAME.value来获取文本。它根本不适合我,我已经尝试了我能想到的每一种解决方法。有什么建议?我的代码是否有问题(我知道它很乱......)?

1 个答案:

答案 0 :(得分:0)

在处理函数中获取窗口小部件值的“正常”方式是e.parameter.widgetName形式,所以在这种情况下你应该只使用

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