我覺得我瘋了,試圖讓最簡單的事情工作!我在Google雲端硬盤上的Google電子表格中有一個郵寄列表。我創建了一個用戶界面,用於提示用戶想要包含在電子郵件中的消息。我的代碼看起來像這樣。從textarea獲取文本
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獲取文本。它根本不適用於我,我嘗試了所有我能想到的解決方法。有什麼建議麼?我的代碼有問題嗎(我知道這很麻煩......)?
請不要在問題中寫下「絕望」,「緊急」等。你怎麼知道你的需要比任何人都更重要? – occulus 2013-03-24 07:22:41
對不起,我不是說我的任務比其他任何人都迫切。我的意思是,我事實上是絕望的(2天調整這一件事,但沒有運氣),因爲修補程序建議在互聯網上我不能去工作(可能是由於我的一些愚蠢的疏忽) - 儘管如此,我有點絕望。 – user2091307 2013-03-24 07:34:25